Sep 25th, 2006, 09:29 AM
Sharing Command object between SimpleFormControllers
I have a Spring MVC application with a SimpleFormController (A). A's successView (B) should be a SimpleFormController itself, and should share the A's Command object as well as the model data that A returns in its onSubmit method ( return new ModelAndView(getSuccessView(), "model", model).addObject(command); ).
I have tried to solve this by using a RedirectView, but neither the Command object or the model data seem to be available in B's formView.
How could I solve this?
Do I have to use a wizard controller?
Sep 27th, 2006, 03:10 AM
AbstractWizardFormController is probably the answer
As far as I can see, AbstractWizardFormController is a solution. See http://www.devx.com/Java/Article/22134/0/page/5.
Sep 27th, 2006, 07:35 AM
There are other ways but wizard controller is very easy to use and seems to be what you need. It's very easy to use the only problems i've had with it are related to customized back behavior.
Sep 27th, 2006, 03:41 PM
What about using session in this case. I use session and it work OK
Last edited by shoa; Sep 27th, 2006 at 05:46 PM.
Oct 4th, 2006, 12:44 PM
How do you use session, could you please explain?
I figured that doing a redirect to a(nother) SimpleFormController of course ends up with an action for the new Form view to be a HTTP GET (as a result of the redirect), which means that I can do a POST to the SimpleFormController.
Could this be overridden in any way, or is wizard controller the answer?
Oct 4th, 2006, 03:44 PM
I think that in your case, AbstractWizardFormController is good choice
Oct 5th, 2006, 04:18 AM
In your first SimpleFormController's onSubmit()-method put your model-object to HttpSession:
Originally Posted by mortenhaugen
and in the 2nd SimpleFormController's formBackingObject() -method read the object from the session by
YourModel model = (YourModel) req.getSession().getAttribute("model");
Beware that formBackinObject() method is called both on form open (request) and on form submit (post).