My controller has a method to return a form backing object:
@ModelAttribute(“userData”)
public UserData formBackingObject() {
return new UserData();
}
When the form submission fails its validation checks, it is redisplayed but when it is re-rendered, the userData object does not contain the user-submitted values – only the values present upon initialiation above.
@RequestMapping(method = RequestMethod.POST)
public void userData(HttpServletRequest request, @ModelAttribute(“userData”) UserData userData, BindingResult bindResult, ModelMap model) {
// do validation checks
if (bindResult.hasErrors()) {
// perform redirect back to same page
}
return "userData";
}
You need to do a model.addAttribute(“key”, value) . This will help bind the values to the model object check http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html for sample.