Skip to content

Instantly share code, notes, and snippets.

@oscarryz
Last active December 21, 2015 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save oscarryz/6381954 to your computer and use it in GitHub Desktop.
Save oscarryz/6381954 to your computer and use it in GitHub Desktop.
Pass the errors to the handling redirect controller using flassAttributes
@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