Struts and Tiles - Steps to use Struts and Tiles

By: Grenfel  

  1. Add TilesRequestProcessor to struts-config.xml
    <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" />
  2. Define the Tiles Plugin
    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
    <set-property property="moduleAware" value="true"/>
    </plug-in>
  3. Create an empty Tiles definition file tiles-defs.xml under /WEB-INF directory
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE
    tiles-definitions PUBLIC
    "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
    "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
    <tiles-definitions>
    </tiles-definitions>
    d) Add the base definition to the tile definition xml

    <definition name="base.definition" path="/Layout.jsp">
    <put name="title" value=""/>
    <put name="header" value="/common/header.jsp" />
    <put name="footer" value="/common/footer.jsp" />
    <put name="body" value="" />
    </definition>
  4. Create the definition for each of the three pages by extending the above definition and overriding the empty values
    <definition name="search.page" extends="base.definition">
    <put name="title" value="Customer Search and List"/>
    <put name="body" value="/CustomerSearchList.jsp" />
    </definition>
    <definition name="customer.page" extends="base.definition">
    <put name="title" value="XYZ Co. Please enter your details"/>
    <put name="body" value="/CustomerForm.jsp" />
    </definition>
    <definition name="dberror.page" extends="base.definition">
    <put name="title" value="An error occured"/>
    <put name="body" value="/DatabaseError.jsp" />
    </definition>
  5. Change the references to physical jsps in struts-config.xml and replace them with one of the above names. For instance, change all references to “/CustomerForm.jsp” as “customer.page” [No “/” is required with Tiles.]



Archived Comments

1. i have been trained in java stream. But i dont know anything in java. a girl is needed to teach me.
View Tutorial          By: savio at 2013-01-23 10:15:51

2. can you explain me clearly about struts-config file
View Tutorial          By: hanisa at 2012-04-26 06:25:17

3. steps 2 create and use tiles
View Tutorial          By: sasank at 2008-10-03 08:06:43


Most Viewed Articles (in Struts )

Latest Articles (in Struts)

Comment on this tutorial