Java Reference
In-Depth Information
Everything is fairly straightforward about the registration process, ex-
cept for two issues that are raised by wizard forms:
1. With required fields on the different pages of a wizard, how do
we prevent the required fields that are in page 2 from causing
validation errors when the user submits the form that's on page 1?
2. When the user has submitted the form on page 1 and moves on
to page 2, how do we “remember” the values that were submitted
on page 1? Where do we store the accumulated values so that we
can retrieve them and save everything at the end of the wizard?
Fortunately, Stripes has built-in support for wizards and deals with
these issues for us. The first thing you have to do is add the @Wizard
annotation to the action bean class:
@Wizard
public class RegisterActionBean ...
As illustrated in Figure 10.6 , on the following page, we have forms in
register.jsp and aliases.jsp that are associated to RegisterActionBean . When
Stripes sees an <s:form> tag for which the action bean is annotated
with @Wizard , it generates some special values in the form to keep track
of what's going on between each page of the wizard. When a form is
submitted, Stripes detects which input fields were in the form and does
not generate required-field validation errors for fields that are not in
the form. That takes care of issue #1. For issue #2, Stripes generates
hidden inputs that contain all the values that have been submitted in
the previous pages of the wizard so that they are “carried over” as the
user goes through the pages of the wizard. When the user submits the
the last page, it's as if the user had submitted one big form with all the
input fields filled in. You can save the data in the action bean just like
you would for a regular single-page form.
That's a lot going on behind the scenes, but from our point of view, all
we had to do was add one annotation, and the wizard is almost ready.
Looking again at Figure 10.6 , on the next page, notice that the view ( )
and done ( ) events are not called from a form. Indeed, view ( ) is called
from a plain link to RegisterActionBean (to start the process), and done ( )
is called from a redirect after saving the registration data.
When an event handler of a @Wizard action bean is called, Stripes looks
for the special values that it generated within the <s:form> tag. To pre-
vent malicious users from bypassing the wizard process, Stripes throws
an exception if those special values are missing. But we can still tell
 
 
Search WWH ::




Custom Search