package org.nutz.mvc.adaptor.injector;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.lang.Mirror;
import org.nutz.lang.Strings;
import org.nutz.lang.inject.Injecting;
import org.nutz.mvc.adaptor.ParamInjector;
import org.nutz.mvc.annotation.Param;

public class ObjectPairInjector implements ParamInjector {

	protected Injecting[] injs;
	protected String[] names;
	protected Mirror<?> mirror;

	public ObjectPairInjector(String prefix, Class<?> type) {
		prefix = Strings.isBlank(prefix) ? "" : Strings.trim(prefix);
		this.mirror = Mirror.me(type);
		Field[] fields = mirror.getFields();
		this.injs = new Injecting[fields.length];
		this.names = new String[fields.length];
		for (int i = 0; i < fields.length; i++) {
			Field f = fields[i];
			this.injs[i] = mirror.getInjecting(f.getName());
			Param param = f.getAnnotation(Param.class);
			String nm = null == param ? f.getName() : param.value();
			this.names[i] = prefix + nm;

		}
	}

	public Object get(HttpServletRequest req, HttpServletResponse resp, Object refer) {
		Object obj = mirror.born();
		for (int i = 0; i < injs.length; i++) {
			Injecting inj = injs[i];
			String[] ss = req.getParameterValues(names[i]);
			if (null == ss)
				continue;
			inj.inject(obj, ss);
		}
		return obj;
	}
}

@@ -1234,37 +1234,8 @@
  %7B%0D%0A
-%09%09%09Injecting inj = injs%5Bi%5D;%0D%0A
 %09%09%09S
@@ -1323,16 +1323,20 @@
 %0D%0A%09%09%09inj
+s%5Bi%5D
 .inject(

Update the code of ObjectPairInjector