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"/>
  3. Create an empty Tiles definition file tiles-defs.xml under /WEB-INF directory
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    tiles-definitions PUBLIC
    "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
    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="" />
  4. Create the definition for each of the three pages by extending the above definition and overriding the empty values
    <definition name="" extends="base.definition">
    <put name="title" value="Customer Search and List"/>
    <put name="body" value="/CustomerSearchList.jsp" />
    <definition name="" extends="base.definition">
    <put name="title" value="XYZ Co. Please enter your details"/>
    <put name="body" value="/CustomerForm.jsp" />
    <definition name="" extends="base.definition">
    <put name="title" value="An error occured"/>
    <put name="body" value="/DatabaseError.jsp" />
  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 "" [No "/" is required with Tiles.]

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in Struts )

Latest Articles (in Struts)