Hi all.
Fairly new to Spring. I'm making a project that does not use Spring Web Flow, but is using the new annotation style in Spring 2.5.
I have a form which I validate and, if there are errors, I go back into the form to fix them. The problem is that when I do so, the ugly browser pop-up asking to re-post the data comes up.
I've tried returning a redirect: url, but doing that loses all the error messages that come up from validation.
Is there an easy way to avoid this behavior?
Code:@Controller @RequestMapping("edit") public class EditController { @RequestMapping(method=RequestMethod.GET) public String showPage(@RequestParam(value="start", required=false) Boolean start, HttpSession session, ModelMap map) { if (start != null && start) map.put("start", true); else map.put("start", false); return "edit"; } @ModelAttribute("myObject") public Notification getObject(@RequestParam(value="start", required=false) Boolean start, HttpSession session) { if (start != null && start) { return new MyClass(); } return (MyClass)session.getAttribute("myObject"); } @RequestMapping(method=RequestMethod.POST) public String submit(HttpSession session, ModelMap map, @ModelAttribute("myObject") MyClass myObject, BindingResult result, SessionStatus status) { new MyValidator().validate(myObject, result); result.setNestedPath(""); if (result.hasErrors()) { map.put("myObject", myObject); return "redirect:edit"; } session.setAttribute("myObject", myObject); status.setComplete(); return "redirect:confirm"; } }


Reply With Quote