Expert Spring MVC and Web Flow

(Dana P.) #1
value="/WEB-INF/jsp/home.jsp"/>
</bean>


value="/WEB-INF/jsp/listFlights.jsp"/>


Making ViewResolvers Known to the Dispatcher


You can define any number of ViewResolvers in your application depending upon your cir-
cumstance. A ViewResolverdefinition resides in the Dispatcher servlet’s configuration file
(WEB-INF/servletName-servlet.xml by default) and is picked up by the dispatcher based on
its class type. Listing 7-11 shows a snippet of the DispatcherServletcontext file defining a
ViewResolver.


Listing 7-11.Configuring a ViewResolver in the Context File



class="org.springframework.web.servlet.view.InternalResourceViewResolver">
value="org.springframework.web.servlet.view.JstlView"/>





■Tip Originally, a ViewResolverdefinition in the dispatcher context file had to take the name
viewResolver.This is still common but no longer required as the servlet will find all ViewResolvers
by type. If you reallywant it, you can revert to the old behavior by setting the detectAllViewResolvers
property of the DispatcherServletto false.


Chaining ViewResolvers with the Ordered Interface


If you elect to use more than one ViewResolverit’s normally because you want to provide
a specific type of resolver for a category of views, perhaps PDFs, falling back to the default
resolver for everything else. This is referred to as chainingViewResolvers. Whatever the reason
for needing different resolvers, you probably want to be in control of the order in which the
DispatcherServletconsults them.
In Spring, many classes of object implement the generic Orderedinterface. This is a sim-
ple interface that defines a single method, getOrder() : int. Groups or collections of objects


CHAPTER 7 ■THE VIEW LAYER 213
Free download pdf