You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

About Tiles

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 following steps must be taken in order to enable tiles support within your Struts2 application:

  1. Include the struts-tiles-plugin as a dependency in your web application. If you are using maven2, the dependency configuration will be similar to:
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-tiles-plugin</artifactId>
      <version>${version.tiles}</version>
      <scope>compile</scope>
    </dependency>
    
  2. Register the tiles listener. This listener will typically either be the standard tiles listener (org.apache.tiles.listener.TilesListener) or the Struts2 replacement (org.apache.struts2.tiles.TilesListener). The latter provides tighter integration with Struts features such as freemarker integration.
    <listener>
      <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>
    
  3. All package definitions which require tiles support must either extend the tiles-default package or must register the following result type definition.
    <result-types>
      <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
    </result-types>
    
  4. Configure your actions to utilize a tiles definition:
    <action name="sample" class="org.apache.struts2.tiles.example.SampleAction" >
      <result name="success" type="tiles">tilesWorks</result>
    </action>
    
  • No labels