Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.