Skip to content

Instantly share code, notes, and snippets.

@javajack
Forked from oscarryz/gist:6381954
Created December 23, 2013 18:32
Show Gist options
  • Save javajack/8102243 to your computer and use it in GitHub Desktop.
Save javajack/8102243 to your computer and use it in GitHub Desktop.
Spring Redirect After Post With Flash Scope
@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