Listing 17-25. Configure Tiles Support in Spring MVC
<?xml version="1.0" encoding="UTF-8"?>
<!-- Other code omitted -->
<!-- Remove the following bean -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jspx" />
</beans:bean>
<!-- Other code omitted -->
<!-- Add the following beans -->
<!-- Tiles Configuration -->
<beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver"
id="tilesViewResolver">
<beans:property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</beans:bean>
<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
id="tilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/layouts/layouts.xml</beans:value>
<!-- Scan views directory for Tiles configurations -->
<beans:value>/WEB-INF/views/**/views.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
</beans:beans>
In Listing 17-25, the bean you need to remove is in italics, while the new bean definitions are in
bold. First, the original ViewResolver bean (with the InternalResourceViewResolver class) is removed.
Then, a ViewResolver bean with the class UrlBasedViewResolver is defined, with the property viewClass
set to the TilesView class, which is Spring MVC's support for Tiles. Finally, a tilesConfigurer bean is
defined that provides the layout configurations required by Tiles.
One final configuration file we need to prepare is the /WEB-INF/views/contacts/views.xml file,
which defines the views for the contact application in our sample. Listing 17-26 shows the file content.
Listing 17-26. The views.xml File
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration
2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition extends="default" name="contacts/list">
<put-attribute name="body"
value="/WEB-INF/views/contacts/list.jspx" />
</definition>
</tiles-definitions>
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home