Expert Spring MVC and Web Flow

(Dana P.) #1
Each form can also specify which page it is in the work flow by including a _pageXXX
request parameter. By default, the wizard tracks the current page in the HTTP session, but to
correctly support the back button, your form should include the _pageXXXparameter. Just like
with _targetXXX, replace XXXwith the number of the current page.
Listing 6-63 says that the current form represents the first page, and the user should be
directed to the second page on a successful form submission.

Listing 6-63.Declaring Current Page and Next Page Numbers

<input type="hidden" name="_page0" value="true" />
<input type="hidden" name="_target1" value="true" />

It is easy to argue that giving the client the responsibility for specifying the target page is
a security concern. For instance, it is easy to specify any target on a form submission. When
precise control over page progression is required, implement the getTargetPage()method to
perform the correct heuristics for target page determination. If you do this, be sure to take into
account support for the Back button of the client’s browser. In other words, don’t base your
decision for the target page solely on information in the session, which isn’t necessarily
updated when the user clicks the Back button.
We keep talking about page numbers, but what do they represent? The wizard is config-
ured with a set of view names, or page names, generally in the order that they should be
presented to the user. The page number is the index into the array of view names.

■NoteThe wizard does not enforce the order of the page views, so each page is free to specify any
target page to go to next. In other words, just because the user is on page 2 does not mean she must view
page 3 next.

For instance, consider the account example mentioned at the beginning of this section.
We require two pages, one for username and email, and the other for billing information.
When we configure the Controller, we specify these page names in order.
The configuration can be performed inside the Controller’s constructor, shown by
Listing 6-64.

Listing 6-64.Constructor Configuration

public CreateAccountWizardController() {
setPages(new String[]{"usernameAndEmail", "billingDetails"});
}

Or inside the bean definition, as is the case with Listing 6-65.

Listing 6-65.XML Configuration

<bean name="/createAccount"
class="com.apress.expertspringmvc.flight.web.CreateAccountWizardController">
<property name="pages">

178 CHAPTER 6 ■THE CONTROLLER MENAGERIE

Free download pdf