Announcement Announcement Module
Collapse
No announcement yet.
Spring FormController lacks POST -> REDIRECT support. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring FormController lacks POST -> REDIRECT support.

    Currently it is good practice to redirect to a success page after submitting a form. Often redirecting to the same page. The redirect ensures that if the user hits reload the page is not resubmitted.

    I know the RedirectView, but unfortunatly I loose the command object when I do that. Then I should retrieve it again from the DB in order to show the confirmation page. Is there any way to incorperate functionality into Spring to support redirecting after POST without loosing the command-object?

    Thanks,
    Vincent

  • #2
    We had the same problem. Our workaround was to extend SimpleFormController and add a saveModel and getModel method that stores and retrieves any model from the session. We call saveModel from onSubmit and getModel from referenceData.

    public abstract class OurSimpleFormController extends SimpleFormController
    {
    protected void saveModel(HttpServletRequest request, String modelName, Object model )
    {
    HttpSession session = request.getSession();
    session.setAttribute(modelName, model);
    }
    protected Object getModel(HttpServletRequest request, String modelName)
    {
    HttpSession session = request.getSession();
    Object model = session.getAttribute( modelName);
    if(model != null)
    {
    session.removeAttribute( modelName);
    }
    return model;
    }
    }

    Comment


    • #3
      Thanks for the reply. I used a simular solution. But thats not a total solution. In my form I use PropertyEditorSupport objects to parse and format my properties.

      Because of the inherent archtecture of AbstractFormController when using a redirect I need to run the success view through a different controller. So, I do not only loose my control object, which I then need to retrieve somehow, I also need to definy my propertyEditors twice if I want to format my data. Not to mention that I then have to pervert the SimpleFormController in a wicked manner that it only renders a success page (poor thing)... I guess I miss some support for this way of handeling form submissions.

      Comment

      Working...
      X