Categories
Development

Struts and multipage forms

At work I haven been pounding out Struts based pages lately. We are building a registration system basically, with some intrisic rules for submitting data and checking with external systems. From my work with Struts at UKA I knew multipage forms were a common problem with Struts. Henning hacked his way around it some way, but I didn’t have to figure it out then.

Struts 1.2 is in the pipeline. It’s running at version 1.2.1 Beta and features several improvements, including support for multipage forms.

The biggest problem with multipage forms were actually the validation. You couldn’t validate the form partially for the first page, and the rest on the second page. This has been solved through the page=”” attribute on the field element in validation.xml. When validation is triggered it will validate the data for the current page AND all pages with a lower number. So this means that if data was validated on page one, it will be validated again together with the data from page two. This also means that if you have implemented your form reset method correctly you will need to include the fields from the previous forms as hidden fields in the current page.

The way Struts keeps track of which page you are on is through the page form attribute. This is just a normal form-field, but its name is required to be page. They should probably have chosen a less generic name for it like struts.form.page or something, but I guess it works fine. It is normally implemented through html:hidden.

5 replies on “Struts and multipage forms”

So I am not sure what you are revealing here. Does Struts 1.2.1 have a solution and if so, how does it do it? Will developers still have to keep track of the page attribute manually, or will things get easier? Please expand.

The developer has to keep track of of the pagenumber through a html:hidden form he types in manually. The big change considering this is that the validation will only trigger for the fields on the currentor previous pages.

It doesn’t actually. They way I solve this in my current code is to set validation=”false” on my action mapping, and explicitly call form.validate() in my actions. If I detect that the validation fails I forward to a specific ationforward. The way I choose to develop pages, it’s impossible to rely on just one input page.

Hi all,

I’m currently using struts v1.2.7. I have three different input forms, but don’t know how to sepparate them. Please could anyone help me to fix that.
Thanks,
Hoang

Leave a Reply

Your email address will not be published. Required fields are marked *