f-angi
2/25/2016 - 8:20 AM

If validation is performed during the Action phase, having @ModelAttribute as a parameter in the Render phase clears the validation errors,

If validation is performed during the Action phase, having @ModelAttribute as a parameter in the Render phase clears the validation errors, so you have to pass the Errors from @ActionMapping to @RenderMapping.

@ActionMapping(params = {
    "action=submit-polizza-search"
})
public void submitSearch(ActionRequest actionRequest, ActionResponse response, 
      @ModelAttribute Denuncia denuncia, BindingResult bindingResult, Model model) {
    if (bindingResult.hasErrors()) {
        model.addAttribute("errors", bindingResult);
        return;
    }
}

@RenderMapping
public String search(RenderRequest request, RenderResponse response, 
      @ModelAttribute Denuncia denuncia, BindingResult bindingResult, 
      SessionStatus sessionStatus,  ModelMap modelMap) {
    Errors errors = (Errors) modelMap.get("errors");
    if (errors != null) {
      bindingResult.addAllErrors(errors);
    }
}