Announcement Announcement Module
Collapse
No announcement yet.
Newbie: How can I submit, but stay on the same form? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie: How can I submit, but stay on the same form?

    My web app comprises of just one form, with a set of lists, and tables of checkboxes.
    The user specifies a filter by selecting items from the lists/tables, and submits the form.
    Rather than going to another form, I need to redisplay the initial form, with the state of the lists/tables maintained, and the results shown in a panel below the filters.

    I have created a formBackingObject that holds the contents of the table of check boxes, when I submit the form I can see the values getting to the onSubmit method via the command object, but when the form is redisplayed, their state has been lost.

    I have set sessionForm to be true, but the formBackingObject method is being called every time the form is displayed, thus overwriting the state values I had in the command object.
    How can I maintain the forms state?

    Thanks Andrew

  • #2
    Do you redirect or forward to yourself again after the submit? Spring 1.1.3 has a forward: syntax, and if this works as in Struts then I assume that the whole context stays the same. Not sure though, I haven't upgraded yet, but it might be worth a try.

    S.

    Comment


    • #3
      Currently I redirect

      I use this: <property name="successView"><value>redirect:HarppsBrowser.h tm</value></property>

      and this in onSubmit:
      getSuccessView()

      So that would be a redirect, I'll upgrade Spring and give your suggestion a try - thanks

      Comment


      • #4
        forward: causes an infinite loop!

        Changing
        <property name="successView"><value>redirect:HarppsBrowser.h tm</value></property>
        to
        <property name="successView"><value>forward:HarppsBrowser.ht m</value></property>

        causes an infinite loop, I assume because the context is kept the same, just keeps calling onSubmit, without rendering the page.

        I didn't think what I was doing was going to be such a struggle!

        Comment


        • #5
          Aha!

          I have changed the successView to the name of the jsp file:
          Code:
          <value>forward&#58;/WEB-INF/jsp/HaRPPS_Browser.jsp</value>
          and return this from onSubmit:
          Code:
          return new ModelAndView&#40;getSuccessView&#40;&#41;,this.getCommandName&#40;&#41;,commandObject&#41;;
          It seems to work!

          Comment


          • #6
            Another thing you can do was mentioned in this thread http://forum.springframework.org/showthread.php?t=11993

            Simply call showForm() again, instead of forwarding or redirecting to yourself. Make sure your form has it's session property set to true and you command object will survive and be reused in its current state.

            Simpler than I thought

            S.
            Last edited by robyn; May 19th, 2006, 04:57 AM.

            Comment

            Working...
            X