@ModelAttribute
uses @RequestParam
for each variable inside the Pojo class
and @RequestParam
uses request.getParameter()
(Am I Correct??).
But from Spring MVC Documentation it's sure that @ModelAttribute
populates the request parameters to bind to argument fields.
But my question is if
pojo
class is ageneric
class then it's not possible to get the parameters,Why?- Is it because the type is considered as
Object
always instead of passed argument type(Pojo). - Is request object/mapping of variables is not capable of handling
Generics
?
- Is it because the type is considered as
- If its a
Wrapper
class than it will work fine because it will be sure about the param type(i.e Pojo class).
Sample Code to check:
Controller
@RequestMapping(value = "/generic", method = RequestMethod.GET)
public String generic(@ModelAttribute Generic<ParamClass> generic) {
return null;
}
@RequestMapping(value = "/wrapper", method = RequestMethod.GET)
public String wrapper(@ModelAttribute WrapperClass wrpr) { //wrpr contains value
return null;
}
Wrapper Class
public class WrapperClass {
private ParamClass paramList;
//getter & setter
}
Generic class
public class Generic<T> {
private T paramList;
//getter & setter
}
Pojo Class
public class ParamClass {
private String param;
// getter & setter
}
Jsp form
<form action="/wrapper">
<table>
<tr>
<td><input type="text" name="paramList.param" /></td>
</tr>
</table>
<input type="submit" value="Submit">
</form>
So one more question is,is it always required to have Wrapper
class for each type? Is there any better solution(except having all param type variables in one class)?