Spring MVC Wizards & Form Taglib
I've been building a JSP based website for a course module titled "Technologies for Electronic Commerce". It's finished now, but I've only just got round to writing up this post.
As part of this I was trying to make a multi-page form, using Spring's AbstractWizardFormController and spent an hour or so trying to make the form submission change the form page. My problem was that it wasn't immediately obvious how to use the form taglib with the Wizard architecture.
The docs mentioned using request parameters, which was a bit confusing as I was using a POST form submission, however all you actually need to do is add one of these parameters to the form data (usually using a button).
Finish and cancel actions can be triggered by request parameters, named PARAM_FINISH ("_finish") and PARAM_CANCEL ("_cancel"), ignoring parameter values to allow for HTML buttons. The target page for page changes can be specified by PARAM_TARGET, appending the page number to the parameter name (e.g. "_target1"). The action parameters are recognized when triggered by image buttons too (via "_finish.x", "_abort.x", or "_target1.x").
For example:
<input value="Submit" name="_target1" type="submit"/>This will request to change to page 2 of the form (remember Array base is 0).
Because of the way forms work, you can have a number of these (either as clickable images or buttons) and only the one the user eventually selects will be submitted with the request.
Labels: form, java, jsp, programming, spring framework
