Expert Spring MVC and Web Flow

(Dana P.) #1
<%= special.getArriveAt().getName() %> from
$<%= special.getCost() %>
</li>
<%
}
%>
</ul>
</body>

Naturally, this is a bit “last century”; we don’t want to be coding Java in our JSPs but it
serves to demonstrate how the Controller, View, ViewResolver, and implementing technology
work together in a simple end to end example. Let’s see how to use the preferred JSP Standard
Tag Library ( JSTL) view to give us a nice, clean syntax.
A simple change to our ViewResolverdefinition from Listing 8-1 denotes that we will use a
subclass of InternalResourceViewwhich adds JSTL support: <property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"/>. Now we can make the amend-
ments to our JSP shown in Listing 8-5.

Listing 8-5.JSTL Displays Our Specials List

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
...
<body>
<h1>Welcome to the Flight Booking Service</h1>

<p>We have the following specials now:</p>

<ul>
<c:forEach items="${specials}" var="special">
<li>
${special.departFrom.name} -
${special.arriveAt.name} from
$${special.cost}
</li>
</c:forEach>
</ul>

<p><a href="search">Search for a flight.</a></p>
</body>

Much better. Figure 8-1 shows the output.

226 CHAPTER 8 ■SUPPORTED VIEW TYPES

Free download pdf