I was facing the same problem. You can use the following code for same
/**
* This method populates bean object properties from the request
* parameters having same name. Hence it is equivalent of
* <jsp:setProperty name="beanId" property="*"/>
* @param HttpRequest The servlet request containing parameters
* @param Bean object implementing Serializable
*/
public void populateBean(HttpServletRequest request, Serializable beanToBePopulated)
{
Enumeration enum = request.getParameterNames();
String name;
String[] values;
int i = 0;
while (enum.hasMoreElements())
{
name = (String)enum.nextElement();
values = request.getParameterValues(name);
for (i = 0; i < values.length; i++)
{
try
{
Class beanClass = beanToBePopulated.getClass();
Class fieldClass = beanClass.getDeclaredField(name).getType();
String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
Method method = beanClass.getMethod(methodName, new Class[]{fieldClass});
method.invoke(beanToBePopulated, new Object[]{values[i]});
}
catch (NoSuchMethodException e){}
catch (java.lang.reflect.InvocationTargetException e){}
catch (IllegalAccessException e){}
catch (NoSuchFieldException e){}
}
}
}
Comments welcome.
Regards,
Bhushan