Announcement Announcement Module
No announcement yet.
POST GET Redirect - form errors Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • POST GET Redirect - form errors

    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?

    public class EditController {
       public String showPage(@RequestParam(value="start", required=false) Boolean start, HttpSession session, ModelMap map)
          if (start != null && start)
             map.put("start", true);
             map.put("start", false);
          return "edit";
       public Notification getObject(@RequestParam(value="start", required=false) Boolean start, HttpSession session)
          if (start != null && start)
             return new MyClass();
          return (MyClass)session.getAttribute("myObject");
       public String submit(HttpSession session, ModelMap map, @ModelAttribute("myObject") MyClass myObject,
             BindingResult result, SessionStatus status) {
          new MyValidator().validate(myObject, result);
          if (result.hasErrors())
             map.put("myObject", myObject);
             return "redirect:edit";
          session.setAttribute("myObject", myObject);
          return "redirect:confirm";