Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController with multiple bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController with multiple bean

    Hi, my application need to post a form with one bean, to bind the parameters in the request to this bean, and then to retrieve another instance of this bean to pass it back to the view.
    The issue I have been having here, is that from my understanding, in a SimpleFormController, the bean retrieved by the formBackingObject method, will be the same one than the one spring will use to bind the parameters and pass back to the form in the showForm method after a submit.
    I solved my issue, by overriding the referenceData since this method is executed after the bind process and before the showForm. I add the following code line :
    Code:
    MyNewBean bean= manager.getBean(myNewID);
    BindException bind = new BindException(bean,getCommandName());
    model.put(getCommandName(),bean);
    model.put(BindException.class.getName()+"."+getCommandName(),bind);
    It worked but look for me like a hack more than a standard use of the SimpleFormController. What do the spring team will recommand ?

    Thanks

    Olivier

  • #2
    Re: SimpleFormController with multiple bean

    Originally posted by olivier
    Hi, my application need to post a form with one bean, to bind the parameters in the request to this bean, and then to retrieve another instance of this bean to pass it back to the view.
    The issue I have been having here, is that from my understanding, in a SimpleFormController, the bean retrieved by the formBackingObject method, will be the same one than the one spring will use to bind the parameters and pass back to the form in the showForm method after a submit.
    That's true. SimpleFormController is very specialized controller and is supposed to work with the same bean. You retrieve bean in formBackingObject, controller saves it in the session and repopulates it on form submission.

    If I were You I would prefer to implement my own sublcass of AbstractFormController or even one of CommandControlers. Of course what You did above works - but indeed it's IMHO a hack.

    BTW: Could you tell what do you do such a uncommon thing, why do You need another instance of the form command bean?

    Artur

    Comment


    • #3
      Thanks, I was thinking about doing my own implementation of the controller, but most of the code, will be a pure copy of the SimpleFormController.

      Basically, the application, is used to describe several objects of the same type, using one controller and one form. For exemple, I have 4 cars to describe. My controller, show first a init page, where I can input the number of cars, and then for each car, I show the same form that need to be inputed and finally finish by displaying the successView.

      Olivier

      Comment

      Working...
      X