Results 1 to 5 of 5

Thread: multiple forms, spring:bind tag and form object

  1. #1
    Join Date
    Dec 2004
    Posts
    9

    Default 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. #2
    Join Date
    Dec 2004
    Posts
    12

    Default 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

    Quote 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.

  3. #3
    Join Date
    Dec 2004
    Posts
    9

    Default 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?

  4. #4
    Join Date
    Oct 2004
    Location
    London, UK
    Posts
    13

    Default

    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 at 05:15 AM.
    James Gellately-Smith

  5. #5
    Join Date
    Jan 2005
    Location
    Newcastle, England
    Posts
    10

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

    Quote 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.

Posting Permissions

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