Tuesday, February 5, 2013

Spring MVC 3 + Tiles

Env: spring mvc v3.2
        tiles: v2.2.2

1) add tiles dependencies to the pom


<!-- apache tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</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-jsp</artifactId>
<version>${tiles.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>${tiles.version}</version>
</dependency>
<!-- End apache tiles -->

2) configure view class and tiles definitions file



<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>
 
 <bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"
p:definitions="classpath:tiles-defs.xml" />

3) tiles-defs.xml


<!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 name="baselayout" template="/view/jsp/baseLayout.jsp">
<put-attribute name="header" value="" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/view/jsp/footer.jsp" />
</definition>

<definition name="summary" extends="baselayout">

</definition>

<!-- abc page -->
<definition name="abc.do" extends="baselayout">
<put-attribute name="desc" value="abc" />
<put-attribute name="title" value="abc" />
<put-attribute name="header" value="/view/jsp/header.jsp" />
<put-attribute name="body" value="/view/abc.jsp" />
</definition>

</tiles-definitions>




4) add a controller to handler url /abc.do

No comments:

Post a Comment