Apache Struts 2 Documentation > Home > Guides > Plugin Developers Guide > Tiles Plugin |
The Tiles Plugin is experimental (it depends on the Apache Tiles beta). Feedback is appreciated!
Tiles is a templating framework designed to easily allow the creation of web application pages with a consistent look and feel. It can be used for both page decorating and componentization. |
The Tiles plugin allows actions to return Tiles pages.
The following steps must be taken in order to enable tiles support within your Struts2 application:
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-tiles-plugin</artifactId> <version>${version.tiles}</version> <scope>compile</scope> </dependency>
<listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> </listener>
<result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/> </result-types>
<action name="sample" class="org.apache.struts2.tiles.example.SampleAction" > <result name="success" type="tiles">tilesWorks</result> </action>
This example shows a Tiles layout page using Struts tags:
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <%@ taglib prefix="s" uri="/struts-tags" %> <%-- Show usage; Used in Header --%> <tiles:importAttribute name="title" scope="request"/> <html> <head><title><tiles:getAsString name="title"/></title></head> <body> <tiles:attribute name="header"/> <p id="body"> <tiles:attribute name="body"/> </p> </body> </html>
This plugin does not have any global settings.
This plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib directory. No other files need to be copied or created.