Programming Tutorials

Struts and Tiles - Steps to use Struts and Tiles

By: Grenfel in Struts Tutorials on 2007-09-22  

  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.]





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Struts )

Latest Articles (in Struts)