PDA

View Full Version : Wizard like form - how to handle this in spring (newbie)


Sprang
Apr 27th, 2006, 06:46 AM
Hi,

I have to do what should be a pretty simple thing. However, as I am new to Spring mvc, I am pretty confused as to what is the correct approach to use.

My goal is to have a 4 step form, where by the user would go through either each step (1,2,3 & 4) or just 1, 3 & 4 - so effectively missing out step 2.

I thought about using AbstractWizardController but my limited understanding is that this should be used for a fixed stage wizard - However, maybe I could get round this by overriding getTargetPage...

A second approach would be having a MultiActionController with a method to representing each of the steps. With the exception of the final step (thank you page) each will have a form, so I am not sure if this is possible.

I then thought about using SWF, which has got much praise from this board but am not sure if it is truly needed.

I am sure there are some people out there who have done the above. If you're one of those guys/girls, please let me know how you reach achieved your goal.

Thanks very much :confused:

socotech
Apr 27th, 2006, 07:23 AM
Will your user make the choice of skipping the step? If so, you simply need to add a name="_targetX" to the skip button where 'X' is the step number to skip to.

Sprang
Apr 27th, 2006, 07:40 AM
The step would be skipped based on a form value from the previous step.

Colin Yates
Apr 27th, 2006, 07:48 AM
I thought about using AbstractWizardController but my limited understanding is that this should be used for a fixed stage wizard - However, maybe I could get round this by overriding getTargetPage...

You might like to look at Spring Web Flow as well, but AWFC will do just fine.


A second approach would be having a MultiActionController with a method to representing each of the steps. With the exception of the final step (thank you page) each will have a form, so I am not sure if this is possible.

It is possible, but nowhere near as elegant as SWF/AWFC :)


I then thought about using SWF, which has got much praise from this board but am not sure if it is truly needed.

I would say it is border line. SWF is getting more and more lightweight in terms of XML cost... Have a look at the samples.


I am sure there are some people out there who have done the above. If you're one of those guys/girls, please let me know how you reach achieved your goal.
I have used AWFC to do exactly as you have (although it was a couple of years ago) and found it to be very flexible. The problem is that the more complex the steps involved between the pages, the bigger the controller. As soon as you starting cusomtising the sequence of steps it gets harder etc.

I would probably recommend using SWF; although your use case is probably on top of the fence between AFWC and SWF :)

socotech
Apr 27th, 2006, 11:46 AM
The step would be skipped based on a form value from the previous step.

Okay, so if you still want to use AWFC, you could override getTargetPage(...) to provide a custom target page: http://springframework.org/docs/api/org/springframework/web/servlet/mvc/AbstractWizardFormController.html#getTargetPage(ja vax.servlet.http.HttpServletRequest,%20java.lang.O bject,%20org.springframework.validation.Errors,%20 int)

Sprang
Apr 28th, 2006, 11:36 AM
Thanks for the replies - I am using AWFC and it seems to be working great.