Expert Spring MVC and Web Flow

(Dana P.) #1
Due to our tag files, this page is fairly succinct and easy to read. Another reason for this
is our use of the <spring:nestedPath>tag. We take advantage of it to make the tags for the
address fields a bit easier to read and write. Without the <spring:nestedPath path="account.
billingAddress">tag, the tag:formFieldtags would need to include the entire path to the
fields: <tag:formField name="Street" path="account.billingAddress.street" />. As you
can imagine, this would become verbose and tedious. Not only do we save typing by using
<spring:nestedPath>, but we’re now able to create generic address XHTML code without wor-
rying what the full path to the fields are. For instance, we can use the same chunk of XHTML
to display an address for both a billing address and a shipping address.
Finally, we present the success page to complete the list of JSP required for the wizard,
shown by Listing 6-71.

Listing 6-71.Wizard Success Page

<?<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Account Successfully Created</title>
</head>
<body>

<h1>Account Successfully Created</h1>

<p>
Congratulations, ${account.username}, your account was
created successfully.
</p>

</body>
</html>

Command Bean
Every good wizard needs a command bean that contains all the form fields from all those
pages. Because we are writing a Spring MVC application, we will use the Accountclass from
our domain model. This class contains the username, password, email address, and billing
address of the user.
However, the work flow requires that the user confirm her password, so where does that
form field live? We don’t want to place confirm password inside the Accountclass, because
after the form is submitted successfully, we don’t care about that field anymore. Instead of
allowing the UI requirements to influence the design of the domain model, we will create a
command bean class (Listing 6-72) that contains both the Accountclass and the confirm
password property. This way we can still use the Accountclass and directly populate it from
the request, as well as incorporate any extra fields required for the work flow.

190 CHAPTER 6 ■THE CONTROLLER MENAGERIE

Free download pdf