Announcement Announcement Module
Collapse
No announcement yet.
multiple forms, spring:bind tag and form object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • multiple forms, spring:bind tag and form object

    I have multiple forms in one page and each form will have different url for action. I have separate form controller to process each submission according to the url in the action. My form view where all forms reside is processed by controller just implemented controller interface. I found that I could not use spring:bind tag in this case because the form object can't be found when spring:bind tag is processed. I can work around this problem by puting form object in the request attribute, but this won't work after validation error in one of the forms. Sounds like pretty common problem. What is the best solution for this problem?

    BTW
    It works fine if I don't use spring:bind tag.

  • #2
    Re: multiple forms, spring:bind tag and form object

    The only way I see it would be possible is to use only one form-backing object (form) for all of the forms on the page. Either move all the properties of sub-forms in this single form or expose your sub-forms as properties of the single, super-form.

    This way, your form-backing object should have all the properties and spring:bind should be happy.

    I'll be interested to know alternatives, though!

    ATTA

    Originally posted by smao
    I have multiple forms in one page and each form will have different url for action. I have separate form controller to process each submission according to the url in the action. My form view where all forms reside is processed by controller just implemented controller interface. I found that I could not use spring:bind tag in this case because the form object can't be found when spring:bind tag is processed. I can work around this problem by puting form object in the request attribute, but this won't work after validation error in one of the forms. Sounds like pretty common problem. What is the best solution for this problem?

    BTW
    It works fine if I don't use spring:bind tag.

    Comment


    • #3
      Re: multiple forms, spring:bind tag and form object

      I hacked around and made it work. Here is how I did it.

      1. In handleRequest method of controller for the form view, I created all form objects and put them in both session and request attribute using the command name as attribute name.
      2. In onSubmit method of form controller for the action url, I remove the other form objects in the session attribute if the form submission succeed.
      3. In showForm method of form controller for the action url, I got all other forms from session attributes and added them in request attributes so that spring:bind won't complain it can't find other form objects.

      It seems to work fine, but I think we should have a multipleform controller to handle this in the framework. I want to write one, any thought on design?

      Comment


      • #4
        Hi,

        Have a look at:
        http://forum.springframework.org/showthread.php?t=11086
        We've been having a look at the same problem.
        Last edited by robyn; May 19th, 2006, 05:15 AM.

        Comment


        • #5
          Re: multiple forms, spring:bind tag and form object

          I'm pretty new to all this (about week in) but some of the solutions i've seen in this forum seem pretty complicated to me. I am investigating the option of overriding the createBinder method of my controller and implementing multiple classes extended from ServletRequestBinder.

          Originally posted by smao
          I have multiple forms in one page and each form will have different url for action. I have separate form controller to process each submission according to the url in the action. My form view where all forms reside is processed by controller just implemented controller interface. I found that I could not use spring:bind tag in this case because the form object can't be found when spring:bind tag is processed. I can work around this problem by puting form object in the request attribute, but this won't work after validation error in one of the forms. Sounds like pretty common problem. What is the best solution for this problem?

          BTW
          It works fine if I don't use spring:bind tag.

          Comment

          Working...
          X