Results 1 to 4 of 4

Thread: More commands in a form? (SimpleFormController)

  1. #1
    Join Date
    Aug 2010
    Location
    Budapest
    Posts
    5

    Default More commands in a form? (SimpleFormController)

    Hi!

    I'm using Spring 2.5.5.

    My question is how is it possible to have more forms or one form with more submit buttons on a jsp page?
    Is SimpleFormController able to handle such a scenario? How can I specify more command objects and send the proper command based on which button was pressed?

    Or maybe i misunderstood the command term here and it shouldn't mapped to actions on a page oneToOne?

    Thanks in advance!

  2. #2
    Join Date
    May 2005
    Posts
    288

    Default

    If you've got more than one form on a page only one of them will be sent to the server. This would be the one a submit button was pressed in. If the command object has attributes for all the fields of all the forms, such a page can be handled by one controller. Whether that makes sense depends on the use case.
    One form with multiple submit buttons is an entirely different beast:
    All of the fields will be sent to the server. The simplest way to find out which button was pressed, is arguably WebUtils.hasSubmitParameter().

    HTH

  3. #3
    Join Date
    Aug 2010
    Location
    Budapest
    Posts
    5

    Default

    Thank you for your answer. It does make sense this way - even though it is a little bit weird for me that you have to have all the fields of different forms in one object to be able to handle them in the controller.. is it really the pattern spring developers suggest us?

    An other question meanwhile still with regard the SimpleFormController:

    is it possible to have both the onSubmit and handleRequest methods overrided and still have the desired functionality?

    for me it seems that in case i override the handleRequest method, the onSubmit is never called, all the requests are handled by the handleRequest method...

    how should i fill in the model for the view when it is first loaded then? (in case i have just the onSubmit method but i would like to have a model there even before the form is submitted)

  4. #4
    Join Date
    May 2005
    Posts
    288

    Default

    You can have different command objects with a single controller, but then you have to assign a different URL to every form and configure the controller for every URL.
    The JavaDoc for SimpleFormController (and its super classes) should answer the other questions.

Posting Permissions

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