I have a Spring MVC application where I use data binding to populate a custom form object someForm with the posted values. The interesting part of the controller looks like the following:
@RequestMapping(value = "/some/path", method = RequestMethod.POST)
public String createNewUser(@ModelAttribute("someForm") SomeForm someForm, BindingResult result){
SomeFormValidator validator = new SomeFormValidator();
validator.validate(someForm, result);
if(result.hasErrors()){
...
return "/some/path";
}
}
SomeFormValidator class is implementing Springs org.springframework.validation.Validator interface. While this is great for validating the users input and creating error messages related to the input, this seems to be not well suited to handle more critical errors, which cannot be presented to the user but are still related to a controller input, like a missing hidden field which is expected to be present at post time. Such errors should result in application errors. What is the Spring MVC way to handle such errors?