Expert Spring MVC and Web Flow

(Dana P.) #1











The first thing to point out is the two hidden input fields that control the page flow of the
wizard. We are specifying both _pageand _targetto tell the wizard that the user is viewing
the first page, and the next page in the wizard is the second page.
As you can see, this page balloons in size when you incorporate all of the Spring JSP tags
and appropriate error messaging. We want to take a small diversion from building the wizard
to show you a few ways to handle this large JSP file.


Reducing Repetition with JSP Tag Files and Spring JSP Tags


In Listing 6-66, there is a lot of duplicate code that should be eliminated to not only save
file size but also to increase readability and reduce typing. There are at least two areas in
the file that we can replace with simple tag files, a convenient way in JSP 2.0 to write custom
tags as easily as writing JSP pages. Think of a tag file as a JSP include that can take parameters;
they are very useful when creating reusable blocks of JSP code.


■Tip For more on JSP 2.0 tag files, refer to JavaServer Pages,Third Edition, by Hans Bergsten (O’Reilly, 2003).


If you’ve never heard of JSP 2.0 tag files then don’t worry. If you’ve written any JSP pages
they will look very familiar.
Tag files only work in JSP 2.0–compliant environments. This means, among other things,
that your servlet container must support JSP 2.0 and that your web.xmlfile must specify the
Servlet 2.4 standard by including version="2.4".


■Tip If you are a Tomcat user, make sure you are using Tomcat 5.0 or better to take advantage of the
Servlet 2.4, JSP 2.0, and tag files.


CHAPTER 6 ■THE CONTROLLER MENAGERIE 185
Free download pdf