Hello friends, sometimes you come across with this very unexpected exception.
For eg: In the given code, after execution this exception occurs..
@RequestMapping(value = "addUser")
public String addUser(@ModelAttribute("userForm") UserForm userForm,
ModelMap map, BindingResult results) {
if (results.hasErrors()) {
return "add_user_form";
}
return "add_user_success";
}
//...
}
Exception: java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute.
Solution:
Well basically, Spring expects the BindingResult attribute to be present right after your Model attribute. So if we change the above controller method to:
RequestMapping(value = "addUser")
public String addUser(@ModelAttribute("userForm") UserForm userForm,
BindingResult results, ModelMap map)
This will solve the error.
0 Comment(s)