Upgrade from Tiles 2 to Tiles 3 on Spring MVC 3 application


Dev-Bookmarks Logo

Save up to a workweek a year by efficiently managing your dev bookmarks, on www.bookmarks.dev. Share your favorites with the community and they will be published on Github - Star


I’ve just upgraded the web application that powers Podcastpedia.org to use Apache Tiles 3 instead of Tiles 2. I am particularly interested in the Tiles integration with Velocity for email generation.

Note: You need at least the Spring 3.2 release for this to work.

This occured in three small steps:

  1. upgrade maven dependencies
  2. upgrade tiles elements in the Spring application context
  3. upgrade tiles dtd version

1. Upgrade maven dependencies

What I had to do was just replace the ${tiles.version} in the maven pom.xml file from 2.2.2 to 3.0.1 for the Tiles dependencies I use, and now it looks like this:

<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-extras</artifactId>
			<version>${tiles.version}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-jsp</artifactId>
			<version>${tiles.version}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-servlet</artifactId>
			<version>${tiles.version}</version>
		</dependency>	
		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-template</artifactId>
			<version>${tiles.version}</version>
		</dependency>	
		<dependency>
			<groupId>org.apache.tiles</groupId>
			<artifactId>tiles-el</artifactId>
			<version>${tiles.version}</version>
		</dependency>

2. Upgrad Tiles configuration in Spring application context

The next thing was to upgrade to version 3 the tilesViewResolver and tilesConfigurer in the Spring application context:

....................
<!-- Convenience subclass of UrlBasedViewResolver that supports TilesView (i.e. Tiles definitions) and custom subclasses of it. -->
<!-- Don't forget to set the order if you declared other ViewResolvers 
-->    
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
	<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
	<property name="order" value="#{contentNegotiatingResolver.order+1}" />
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
  <property name="basename" value="views"/>
  <property name="order" value="#{tilesViewResolver.order+1}" />
</bean>

<!-- Helper class to configure Tiles 2.x for the Spring Framework -->
<!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/view/tiles2/TilesConfigurer.html -->
<!-- The actual tiles templates are in the tiles-definitions.xml  -->

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">	
	<property name="definitions">		
		<list>
			<value>/WEB-INF/tile-defs/templates.xml</value>
			<value>/WEB-INF/tile-defs/definitions.xml</value>
		</list>		
	</property>	
</bean>
....................

3. Upgrade tiles.dtd version

In the Tiles definitions templates upgrade to Tiles 3.0 dtd

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">        
<tiles-definitions>  
.........         
</tiles-definitions>

That’s it.

P.S.

For a complete example of Tiles integration with Spring MVC see my post – Spring 3 and Tiles 2 Integration

Discover a collection of more than 10k curated dev bookmarks

We have recently reached a second major milestone on www.bookmarks.dev. There are now more than 10k curated public dev bookmarks available. There are resources for programming languages like java, rust, go, python, for query language like sql, graphql to exotics like genetic-algorithms and astronomy Continue reading

New dev bookmarks in february 2019

Published on March 10, 2019