You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by gr...@apache.org on 2005/11/15 18:28:21 UTC

svn commit: r344398 - in /struts/tiles/trunk/xdocs: examples.xml userGuide.xml

Author: greddin
Date: Tue Nov 15 09:28:15 2005
New Revision: 344398

URL: http://svn.apache.org/viewcvs?rev=344398&view=rev
Log:
Updated Examples documentation.

Modified:
    struts/tiles/trunk/xdocs/examples.xml
    struts/tiles/trunk/xdocs/userGuide.xml

Modified: struts/tiles/trunk/xdocs/examples.xml
URL: http://svn.apache.org/viewcvs/struts/tiles/trunk/xdocs/examples.xml?rev=344398&r1=344397&r2=344398&view=diff
==============================================================================
--- struts/tiles/trunk/xdocs/examples.xml (original)
+++ struts/tiles/trunk/xdocs/examples.xml Tue Nov 15 09:28:15 2005
@@ -25,13 +25,212 @@
 
 <section name="Creating Templates">
 
+    <p>The following examples illustrate Tiles' templating features using a 
+       basic template.  The template contains three elements: a title, a header,
+       and a body displayed vertically.  These elements will be manipulated in 
+       various ways in each example.  Tiles' flexibility will be demonstrated by
+       defining the template "inline" in a JSP page and by loading it from a
+       "factory" defined in an XML file.</p>
+       
     <subsection name="Basic Template">
+    
+    <p>The first example shows the basic template.  There are three ways to 
+       define the template.  First, it can be defined anonymously in a JSP page 
+       by using the Tiles insert tag.  Secondly, it can be defined in a JSP 
+       using the Tiles definition tag.  Finally, it can be defined in an XML
+       file and loaded from a factory using the Tiles insert tag.  This example
+       will illustrate all three methods.  First, let's look at the output of 
+       the example.  Then we will examine each method.</p>
+       
+    <strong>Example Output</strong>
+    <div align="center" width="300" border="2" bordercolor="black" >
+        <table width="100%">
+        <tr>
+        <td  bgcolor="Blue"><strong>This is the title.</strong></td>
+        </tr>
+        <tr>
+        <td><strong>This is the header</strong>
+        <img src="images/struts-power.gif" align="right" border="0"/>
+        </td>
+        </tr>
+        <tr>
+        <td><div align="center"><b><i>This is the body</i></b></div>
+        </td>
+        </tr>
+        </table>
+    </div>
+    
+    <p>First let's look at the template.  The layout.jsp file contains the
+       template code.  This file does not change no matter whether the Tile
+       is defined anonymously, in a JSP, or in an XML definitions file.</p>
+       
+    <strong>file: layout.jsp</strong>
+
+    <source><![CDATA[
+<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
+
+<table  border="2"  width="300"  bordercolor="Gray">
+  <tr>
+    <td  bgcolor="Blue"><strong><tiles:getAsString name="title"/></strong></td>
+  </tr>
+  <tr>
+    <td><tiles:insert attribute="header"/></td>
+  </tr>
+  <tr>
+    <td><tiles:insert attribute="body"/></td>
+  </tr>
+</table>                     
+    ]]></source>
+
+    <p>Next we show the template being inserted anonymously using the Tiles
+       insert tag.  The insert tag is used to define the Tile and insert it in
+       a single action.  The Tile is not placed in the Definitions Factory and
+       is not available for later use.  The template is invoked and the 
+       attributes are filled in.  Notice that the title is inserted directly and
+       the header and body values are included JSP pages.</p>
+       
+    <strong>file: somepage.jsp </strong>
+    <source><![CDATA[
+<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
+
+<tiles:insert template="layout.jsp">
+  <tiles:put name="title"  value="This is the title." />
+  <tiles:put name="header" value="header.jsp" />
+  <tiles:put name="body"   value="body.jsp" />
+</tiles:insert>
+    ]]></source>
+
+    <strong>file: header.jsp </strong>
+    <source><![CDATA[
+<strong>This is the header</strong>
+<img src="<%=request.getContextPath()%>/images/struts-power.gif" align="right" border="0"/>
+    ]]></source>
+
+    <strong>file: body.jsp </strong>
+    <source><![CDATA[
+<div align="center"><b><i>This is a body</i></b></div>
+    ]]></source>
+    
+    <p>Now we will see the same example in a different way.  In this version the
+       Tile is defined in a JSP using the Tiles definition tag.  This works very
+       similarly to the anonymous version.  The only difference is that it is not
+       anonymous.  Using this method the template is included and populated and
+       the Tile is inserted into the Definitions Factory so that it can be used
+       by other JSP pages.</p>
+       
+    <strong>file: somepage.jsp </strong>
+    <source><![CDATA[
+<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
+
+<tiles:definition id="templateDefinition" template="layout.jsp">
+  <tiles:put name="title"  value="This is the title." />
+  <tiles:put name="header" value="header.jsp" />
+  <tiles:put name="body"   value="body.jsp" />
+</tiles:definition>
+<tiles:insert beanName="templateDefinition" />
+    ]]></source>
+
+    <p>Using this method of defining Tiles can be very tricky.  If you define a
+       Tile like this and then insert it in another page using the Tiles insert
+       tag, you must make sure that JSP page will never be invoked before the 
+       page that defines the Tile.  The Tiles Definitions Factory is stored in 
+       application scope.  So if the server is restarted or the Definitions 
+       Factory is reloaded for any reason, a Tile defined in a JSP page is not
+       reloaded until that JSP page is invoked.</p>
+
+    <p>The scenario above can be avoided by defining Tiles in an XML configuration
+       file.  The file is loaded at servlet startup using the Tiles Servlet or
+       a Struts plugin.  The example below defines the Tile in an XML file and
+       uses the Tiles insert tag in a JSP to invoke it.</p>
+
+    <strong>file: WEB-INF/tiles-defs.xml</strong>
+    <source><![CDATA[
+...
+<definition name="templateDefinition" path="/layout.jsp">
+  <put name="title"  value="This is the title." />
+  <put name="header" value="header.jsp" />
+  <put name="body"   value="body.jsp" />
+</definition>
+...
+    ]]></source>
+
+    <strong>file: somepage.jsp</strong>
+    <source><![CDATA[
+<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
+
+<tiles:insert beanName="templateDefinition" />
+    ]]></source>
+    
+    <p>This is the preferred method of defining Tiles.  It ensures that all
+       definitions are loaded at application startup and reduces the coupling
+       between JSP pages.</p>
+       
     </subsection>
     
     <subsection name="Specify Attribute Types">
+       
+    <strong>Example Output</strong>
+    <div align="center" width="300" border="2" bordercolor="black" >
+        <table width="100%">
+        <tr>
+        <td  bgcolor="Blue"><strong>Title with specified Type.</strong></td>
+        </tr>
+        <tr>
+        <td><strong>This is the header</strong>
+        <img src="images/struts-power.gif" align="right" border="0"/>
+        </td>
+        </tr>
+        <tr>
+        <td><div align="center"><b><i>This is the body</i></b></div>
+        </td>
+        </tr>
+        </table>
+    </div>
+    
+    <strong>file: WEB-INF/tiles-defs.xml</strong>
+    <source><![CDATA[
+...
+<definition name="templateDefinition" path="/layout.jsp">
+  <put name="title"  value="Title with specified Type." type="string" />
+  <put name="header" value="header.jsp" type="page" />
+  <put name="body"   value="body.jsp" type="page" />
+</definition>
+...
+    ]]></source>
     </subsection>
     
     <subsection name="Set Attribute With Tag Body">
+       
+    <strong>Example Output</strong>
+    <div align="center" width="300" border="2" bordercolor="black" >
+        <table width="100%">
+        <tr>
+        <td  bgcolor="Blue"><strong>Test with tag body.</strong></td>
+        </tr>
+        <tr>
+        <td>
+          <strong>This header is inserted as body of tag</strong>
+        </td>
+        </tr>
+        <tr>
+        <td><div align="center"><b><i>This is the body</i></b></div>
+        </td>
+        </tr>
+        </table>
+    </div>
+    
+    <strong>file: WEB-INF/tiles-defs.xml</strong>
+    <source><![CDATA[
+...
+<definition name="templateDefinition" path="/layout.jsp">
+  <put name="title"  value="Test with tag body." type="string" />
+  <put name="header" type="string" >
+    <strong>This header is inserted as body of tag</strong>
+  </put>
+  <put name="body"   value="body.jsp" type="page" />
+</definition>
+...
+    ]]></source>
     </subsection>
     
     <subsection name="Using Inheritance:  Overloading parameters">

Modified: struts/tiles/trunk/xdocs/userGuide.xml
URL: http://svn.apache.org/viewcvs/struts/tiles/trunk/xdocs/userGuide.xml?rev=344398&r1=344397&r2=344398&view=diff
==============================================================================
--- struts/tiles/trunk/xdocs/userGuide.xml (original)
+++ struts/tiles/trunk/xdocs/userGuide.xml Tue Nov 15 09:28:15 2005
@@ -408,6 +408,50 @@
     </subsection>
 </section>
 
+<section name="3. Other Resources">
+
+<p>
+<a href="http://www.oracle.com/technology/oramag/oracle/04-may/o34dev_struts.html">
+<strong>Reuse Tiles and Simplify UI</strong></a> 
+by James Holmes. Howto article in Oracle Magazine.
+</p>
+
+<p>
+<a href="http://www.manning.com/getpage.html?project=husted&amp;filename=chapters.html">
+<strong>Developing applications with Tiles</strong></a> by Cedric Dumoulin and 
+Ted Husted.  Sample chapter from
+<a href="http://www.amazon.com/exec/obidos/ISBN=1930110502/hitchhikeguidetoA/">
+Struts in Action</a>; available as a free download (PDF).
+</p>
+
+<p>
+<a href="http://www.oreilly.com/catalog/jakarta/chapter/">
+<strong>Using Tiles</strong></a> Sample beta chapter from
+<a href="http://www.amazon.com/exec/obidos/ISBN=0596003285/hitchhikeguidetoA/">
+Programming Jakarta Struts</a>; available as a free download (PDF).
+</p>
+
+<p>
+<a href="http://www-106.ibm.com/developerworks/java/library/j-strutstiles.html?loc=j">
+<strong>Struts and Tiles aid component-based development</strong></a> by Wellie Chao.
+</p>
+
+<p>
+<a href="http://www.javaworld.com/javaworld/jw-01-2002/jw-0104-tilestrut.html">
+<strong>UI design with Tiles and Struts</strong></a> by Prakash Malani.
+</p>
+
+<p>
+<a href="http://www.theserverside.com/resources/article.jsp?l=Tiles101">
+<strong>Tiles 101/201</strong></a> by Patrick Peak.
+</p>
+
+<p>
+<a href="http://www.lifl.fr/~dumoulin/tiles/tilesAdvancedFeatures.pdf">
+<strong>Tiles Advanced Features</strong></a> by Cedric Dumoulin.
+</p>
+
+</section>
 
 </body>
 </document>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org