I am stuck trying to passing the BindingResult through RedirectionAttributes:
I have referenced Spring - Redirect after POST (even with validation errors), but am still stuck.
I have a GET method:
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(@ModelAttribute("exampleForm") final ExampleForm exampleForm, final Model model)
{
return "test";
}
and a POST method:
@RequestMapping(value = "/doSomething", method = RequestMethod.POST)
public String doSomething(@Valid @ModelAttribute("exampleForm") final ExampleForm exampleForm, final BindingResult bindingResult, final RedirectAttributes redirectAttributes)
{
if (bindingResult.hasErrors())
{
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.exampleForm", bindingResult);
redirectAttributes.addFlashAttribute("exampleForm", exampleForm);
return "redirect:/test";
}
}
However, I am not seeing binding errors in the model of the GET method (after redirect) when I receive them in the POST method - they seem to disappear.
Here is the bindingResult object in the POST method:
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Here is the model entry in the GET method showing 0 errors:
org.springframework.validation.BindingResult.exampleForm=org.springframework.validation.BeanPropertyBindingResult: 0 errors
Any help would be much appreciated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With