Expert Spring MVC and Web Flow

(Dana P.) #1

  • ResourceBundleViewResolveruses view bean definitions in a ResourceBundlein the class-
    path. By default the base name for this bundle is views,so it will be located in a file called
    views.propertiesin the classpath root. ResourceBundleViewResolveris the only resolver
    that supports internationalization via the standard ResourceBundlemechanism.

  • UrlBasedViewResolverexpects the symbolic view name to map directly to a URL with
    optional prefixes and suffixes. Appropriate where arbitrary mapping definitions are
    not required. This resolver acts as a superclass for JSP- and template-based views.


The other ViewResolvers are extensions of the ones just described and specialize the
ViewResolverfunctionality for particular view technologies. Most of these we’ll encounter
later as we discuss the view types themselves that those resolvers are used for. For now we’ll
take a look at two of the non–view-specific resolvers and how to configure them.


ResourceBundleViewResolver


Listing 7-9 shows an extract from a views.propertiesfile. This file, located in the root
of the classpath, can be used to define the views in your application when picked up by a
ResourceBundleViewResolver. We’ll examine some of the concepts being exposed here.


Listing 7-9.Sample views.properties


parent-view.class=org.springframework.web.servlet.view.JstlView
parent-view.(abstract)=true
parent-view.attributesCSV=title=FlightDeals.com,season=Summer


homepage.parent=parent-view
homepage.url=/WEB-INF/jsp/home.jsp
listFlights.parent=parent-view
listFlights.url=/WEB-INF/jsp/listFlights.jsp


■CautionSome of the special properties like abstract(shown in the preceding listing),ref,and
singletonare enclosed in parentheses to distinguish them from properties of the same name that your
class might have. The parent property does not have this requirement, which is inconsistent. This has been
corrected for version 1.3.


Our views.propertiesfile is quite short, but there’s a lot going on under the covers. First,
this is a generic Spring bean definition file. Although using XML is the more typical approach
to defining beans, Spring has always supported property file definitions. From these defini-
tions, three beans would be created in the context with ids:



  • parent-view

  • homepage

  • listFlights


CHAPTER 7 ■THE VIEW LAYER 211
Free download pdf