Results 1 to 3 of 3

Thread: Spring FormController lacks POST -> REDIRECT support.

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Posts
    12

    Default 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. #2

    Default

    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;
    }
    }

  3. #3
    Join Date
    Aug 2004
    Posts
    12

    Default

    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.

Similar Threads

  1. Announcement: Spring IDE WebFlow Support Preview Release 2
    By Christian Dupuis in forum Announcements
    Replies: 2
    Last Post: Sep 15th, 2006, 11:50 AM
  2. New Spring Support Forums are Live
    By Colin Sampaleanu in forum Announcements
    Replies: 17
    Last Post: May 22nd, 2005, 12:57 AM
  3. Announcement: Spring IDE WebFlow Support Preview Release 1
    By Christian Dupuis in forum Announcements
    Replies: 0
    Last Post: May 20th, 2005, 08:15 PM
  4. Spring code remarks
    By Alarmnummer in forum Architecture
    Replies: 18
    Last Post: Apr 7th, 2005, 07:17 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •