Announcement Announcement Module
No announcement yet.
Newbie: How can I submit, but stay on the same form? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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.



    • #3
      Currently I redirect

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

      and this in onSubmit:

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


      • #4
        forward: causes an infinite loop!

        <property name="successView"><value>redirect:HarppsBrowser.h tm</value></property>
        <property name="successView"><value> 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!


        • #5

          I have changed the successView to the name of the jsp file:
          and return this from onSubmit:
          return new ModelAndView&#40;getSuccessView&#40;&#41;,this.getCommandName&#40;&#41;,commandObject&#41;;
          It seems to work!


          • #6
            Another thing you can do was mentioned in this thread

            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

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