views:

1920

answers:

5

Is it possible to have one controller to handle multiple forms in spring?

For example, i have 3 steps registration that map with "/register" url. Is it possible to have only one RegisterController that can handle all registration's steps form submit?

+1  A: 

That depends on the style of controllers you're using. If you use Spring 2.0-style form controllers (e.g. a subclass of SimpleFormController or AbstractFormController), then you might have some difficulty. If, however, you're using Spring 2.5-style annotated @Controllers, then these are very flexible, and you should be able to handle pretty much any cmplexity you desire in one controller class.

skaffman
+2  A: 

Like skaffman said you can use @Controller that are very flexible. But if you're writting a Wizard, you should take a look at AbstractWizardFormController. It handles all steps and validation of a wizard. It also keeps the same backing object for each form submission. When your wizard is on the final action, you can take this object and update it at the database.

You can find an exemple at : http://www.cs.bham.ac.uk/~aps/syllabi/2004%5F2005/issws/h04/spring.html#AbstractWizardFormController

Mike
I read the newest spring doc and I didn't see that. the new spring probably wants people to use the 'spring web flow' thingy.
irreputable
A: 

you will have to use 'MultiActionController', but there are some complication in validation porting if you will use this controller.
Solution of similar problem is given @ http://www.scribd.com/doc/20156448/Multi-Action-Controller-With-Validation

Rakesh Juyal
A: 

you can use Spring webFlow and annotate your controller as @controller

bassem
+1  A: 

https://jira.springsource.org/browse/SPR-5534

yk