Expert Spring MVC and Web Flow

(Dana P.) #1
Work Flow Cancellation
Optionally, you may decide to allow the user to cancel out of the work flow at any time by
overriding the processCancel()method. This allows you to perform any cleanup that might
have built up during the wizard.
The default state change trigger is the presence of a _cancelrequest parameter, but you
may change the heuristics by overriding isCancelRequest().
You do not need to remove the command object from the session, as that is handled for
you by the Controller. At the very least, simply return a ModelAndViewinstance directing the
user to the appropriate page.

Work Flow Completion
This leads us to talk about processFinish(), the only method you must implement with the
wizard controller. When the controller encounters either a _finishrequest parameter, or if
you override isFinishRequest()and return true, the command object is validated again, once
for each page in the work flow. If there are no errors after a full validation, processFinish()is
called, which is where you perform any business logic. As always, you are required to return a
ModelAndView, but note that the view name must be set, as the controller does not populate it
from the list of page names.

Wizard Example
Let’s put together a two-page wizard for the account creation use case mentioned at the
beginning of this section. We’ll fill out this example with the XHTML files for both pages,
the controller itself, and the Validators required. We’re including the Validators so you can
see how the work flow is altered after errors from validation.
First off, Figures 6-5 and 6-6 shows you what the two screens will look like for the end user.

Figure 6-5.Wizard page 1

180 CHAPTER 6 ■THE CONTROLLER MENAGERIE

Free download pdf