-
-
Save javajack/8102243 to your computer and use it in GitHub Desktop.
Spring Redirect After Post With Flash Scope
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