1 package jodd.bean.loaders; 2 3 import java.util.Enumeration; 4 5 import javax.servlet.http.HttpServletRequest; 6 7 import jodd.bean.BeanUtil; 8 9 25 public class RequestLoader implements jodd.bean.Loader { 26 27 public void load(Object bean, Object request) { 28 if (request instanceof HttpServletRequest) { 29 Enumeration paramNames = ((HttpServletRequest)request).getParameterNames(); 30 while (paramNames.hasMoreElements()) { 31 String paramName = (String) paramNames.nextElement(); 32 String[] paramValues = ((HttpServletRequest)request).getParameterValues(paramName); 33 if (paramValues == null) { 34 continue; 35 } 36 if (paramValues.length == 0) { 37 continue; 38 } 39 if (paramValues.length == 1) { 40 BeanUtil.setProperty(bean, paramName, paramValues[0]); 42 } else { 43 BeanUtil.setProperty(bean, paramName, paramValues); 45 } 46 } 47 } 48 return; 49 } 50 } 51 | Popular Tags |