Last active
December 21, 2015 23:28
-
-
Save oscarryz/6381954 to your computer and use it in GitHub Desktop.
Pass the errors to the handling redirect controller using flassAttributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(value = "/hola", method = RequestMethod.GET) | |
public String hola(Model model, | |
@ModelAttribute("command") Object command, | |
BindingResult results, | |
RedirectAttributes redirectAttributes ) { | |
model.addAttribute("command", command); | |
ValidationUtils.invokeValidator(validator, command, results); | |
if (results.hasErrors()) { | |
redirectAttributes.addFlashAttribute("errors", results.getAllErrors()); | |
return "redirect:/ganador/error"; | |
} | |
return "hola"; | |
} | |
@RequestMapping(value = "/error" ) | |
public String error(Model model, | |
@ModelAttribute("command") Object command, | |
BindingResult results, | |
RedirectAttributes ra) { | |
for( ObjectError error : ((List<ObjectError>)model.asMap().get("errors"))){ | |
results.addError(error); | |
} | |
return "error"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment