blob: 522dffb3a745733090e2ddfd03a7742992ca4c59 [file] [log] [blame]
<html>
<head>
<title>VelocityStruts - TilesTool</title>
<meta name="author" value="Marino A. Jonsson"/>
<meta name="email" value="marino@apache.org" />
</head>
<body bgcolor="#ffffff" text="#000000" link="#525D76"
alink="#525D76" vlink="#525D76">
<table border="0" width="100%" cellspacing="4">
<tr><td colspan="2">
<a href="http://jakarta.apache.org/">
<img src="http://jakarta.apache.org/images/jakarta-logo.gif"
align="left" alt="The Jakarta Project" border="0"/>
</a>
<a href="index.html">
<img src="../images/velocitystruts.png" align="right" alt="< Velocity Tools - Struts >" border="0"/>
</a>
</td></tr>
<tr>
<td colspan="2">
<hr noshade="" size="1"/>
</td>
</tr>
<tr>
<td width="20%" valign="top" nowrap="true">
<p><strong><a href="../">Velocity Tools</a></strong></p>
<p>
<strong>VelocityStruts</strong>
</p>
<ul>
<li><a href="index.html">Overview</a></li>
<li><a href="index.html#Benefits">Benefits</a></li>
<li><a href="../index.html#Download">Download</a></li>
<li><a href="userguide.html">User Guide</a></li>
<li><a href="userguide.html#Installation">Installation</a></li>
<li><a href="../index.html#Example Applications">Examples</a></li>
<li><a href="../javadoc/index.html">Javadoc</a></li>
</ul>
<p>
<a href="StrutsTools.html"><strong>VelocityStruts Tools</strong></a>
</p>
<ul>
<li><a href="ActionMessagesTool.html">ActionMessagesTool</a></li>
<li><a href="ErrorsTool.html">ErrorsTool</a></li>
<li><a href="FormTool.html">FormTool</a></li>
<li><a href="MessageTool.html">MessageTool</a></li>
<li><a href="StrutsLinkTool.html">StrutsLinkTool</a></li>
<li><a href="SecureLinkTool.html">SecureLinkTool</a></li>
<li><a href="TilesTool.html">TilesTool</a></li>
<li><a href="ValidatorTool.html">ValidatorTool</a></li>
</ul>
<p>
<strong>Other Subprojects</strong>
</p>
<ul>
<li><a href="../generic/">GenericTools</a></li>
<li><a href="../view/">VelocityView</a></li>
</ul>
<p>
</p>
</td>
<!-- RIGHT SIDE MAIN BODY -->
<td colspan="1" valign="top" align="left">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="TilesTool Reference Documentation">
<strong>TilesTool Reference Documentation</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
The TilesTool is used to interact with the Tiles framework that is now part
of Struts (since v. 1.1).
</p>
<table cellpadding="0" cellspacing="0">
<tr><td colspan="2"><strong>Class</strong></td></tr>
<tr><td>&nbsp;</td><td>org.apache.velocity.tools.struts.TilesTool</td></tr>
<tr><td colspan="2"><strong>Name</strong></td></tr>
<tr><td>&nbsp;</td><td>$tiles (this is the recommended name of the tool in
the Velocity context)</td></tr>
<tr><td colspan="2"><strong>Toolbox Configuration Example</strong></td></tr>
<tr><td>&nbsp;</td><td><pre>&lt;tool&gt;
&lt;key&gt;tiles&lt;/key&gt;
&lt;scope&gt;request&lt;/scope&gt;
&lt;class&gt;org.apache.velocity.tools.struts.TilesTool&lt;/class&gt;
&lt;/tool&gt;</pre></td></tr>
<tr><td colspan="2"><strong>Author(s)</strong></td></tr>
<tr><td>&nbsp;</td><td><a href="mailto:marinoj@centrum.is">Marino A. Jonsson</a><br></td></tr>
</table>
<dl>
<dt><strong>Method Overview</strong></dt>
<dd>
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td bgcolor="EEEEEE" nowrap>
<a href="#importAttributes()">importAttributes()</a></td>
<td bgcolor="EEEEEE">
Imports all attributes in the current tiles definition into the named context
</td>
</tr>
<tr>
<td bgcolor="EEEEEE" nowrap>
<a href="#getAttribute()">getAttribute()</a></td>
<td bgcolor="EEEEEE">
Returns a named tiles attribute from the current tiles definition
</td>
</tr>
<tr>
<td bgcolor="EEEEEE" nowrap>
<a href="#importAttribute()">importAttribute()</a></td>
<td bgcolor="EEEEEE">
Imports a named attribute in the current tiles definition into the
named context.
</td>
</tr>
<tr>
<td bgcolor="EEEEEE" nowrap>
<a href="#get()">get()</a></td>
<td bgcolor="EEEEEE">
Inserts the named tile into the current tile.
</td>
</tr>
</table>
</dd>
</dl>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="importAttributes()">
<strong>importAttributes()</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
<abstract>
Imports all attributes in the current tiles definition into the named context
</abstract>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
void importAttributes()
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
void importAttributes(String scope)
</signature>
</code></font>
</td></tr></table>
</p>
<dl>
<dt><strong>Parameters</strong></dt>
<dd>
<dl>
<dt>scope</dt>
<dd>
<parameter name="scope">
The named context scope to put the attributes into. Possible values
are <code>page</code> (velocity-context), <code>request</code>,
<code>session</code>, and <code>application</code>.
</parameter>
</dd>
</dl>
</dd>
</dl>
<p>This method makes it possible to import all attributes, defined in the
current tiles definition, into any scope, to be accessed i.e. by
other tiles.</p>
<p>Assuming that the tiles config contains the following definition(and ".tilename"
is the current tiles definition):</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>&lt;definition name=".tilename" path="/layout.vm"&gt;
&lt;put name="attr1" value="This is one attribute."/&gt;
&lt;put name="attr2" value="and this is a another."/&gt;
&lt;/definition&gt;</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>then the following Velocity script:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>$tiles.importAttributes()
$attr1
$attr2</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>produces this output:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>This is one attribute
and this is another one</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<br clear="all">
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="getAttribute()">
<strong>getAttribute()</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
<abstract>
Returns a named tiles attribute from the current tiles definition
</abstract>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
String getAttribute(String attributeName)
</signature>
</code></font>
</td></tr></table>
</p>
<dl>
<dt><strong>Parameters</strong></dt>
<dd>
<dl>
<dt>attributeName</dt>
<dd>
<parameter name="attributeName">
The name of the tiles-definition attribute.
</parameter>
</dd>
</dl>
</dd>
</dl>
<dl>
<dt><strong>Returns</strong></dt>
<dd>
<returns>
Returns the named tiles attribute from the current tiles definition
</returns>
</dd>
</dl>
<p>This method makes it possible to fetch any attribute defined in the
current tiles definition.</p>
<p>Assuming that the tiles config contains the following definition (and ".tilename"
is the current tiles definition):</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>&lt;definition name=".tilename" path="/layout.vm"&gt;
&lt;put name="attr1" value="This is one attribute."/&gt;
&lt;put name="attr2" value="and this is a another."/&gt;
&lt;/definition&gt;</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>then the following Velocity script:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>$tiles.getAttribute("attr1")</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>produces this output:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>This is one attribute</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<br clear="all">
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="importAttribute()">
<strong>importAttribute()</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
<abstract>
Imports a named attribute in the current tiles definition into the
named context.
</abstract>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
void importAttribute(String attributeName)
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
void importAttribute(String attributeName, String scope)
</signature>
</code></font>
</td></tr></table>
</p>
<dl>
<dt><strong>Parameters</strong></dt>
<dd>
<dl>
<dt>attributeName</dt>
<dd>
<parameter name="attributeName">
The name of the tiles-definition attribute.
</parameter>
</dd>
<dt>scope</dt>
<dd>
<parameter name="scope">
The named context scope to put the attributes into. Possible values
are <code>page</code> (velocity-context), <code>request</code>,
<code>session</code>, and <code>application</code>.
</parameter>
</dd>
</dl>
</dd>
</dl>
<p>This method makes it possible to import a named attribute, defined
in the current tiles definition, into any scope, to be accessed i.e. by
other tiles.</p>
<p>Assuming that the tiles config contains the following definition(and ".tilename"
is the current tiles definition):</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>&lt;definition name=".tilename" path="/layout.vm"&gt;
&lt;put name="attr1" value="This is one attribute."/&gt;
&lt;put name="attr2" value="and this is a another."/&gt;
&lt;/definition&gt;</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>then the following Velocity script:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>$tiles.importAttribute("attr1")
$attr1</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>produces this output:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>This is one attribute</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<br clear="all">
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="get()">
<strong>get()</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
<abstract>
Inserts the named tile into the current tile.
</abstract>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
void get(Object attr)
</signature>
</code></font>
</td></tr></table>
</p>
<dl>
<dt><strong>Parameters</strong></dt>
<dd>
<dl>
<dt>attr</dt>
<dd>
<parameter name="attr">
The name of the tile to insert.
</parameter>
</dd>
</dl>
</dd>
</dl>
<p>This method makes it possible to insert a named tile, defined
in the current tiles definition, into the velocity template.</p>
<p>Assuming that the tiles config contains the following definition(and ".tilename"
is the current tiles definition):</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>&lt;definition name=".tilename" path="/layout.vm"&gt;
&lt;put name="header" value="/header.vm"/&gt;
&lt;/definition&gt;</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>then the following two Velocity scripts:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>&lt;!-- layout.vm --&gt;
&lt;html&gt;
$tiles.header
&lt;body&gt;
World
&lt;/body&gt;
&lt;/html&gt;</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p/>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>&lt;!-- header.vm --&gt;
&lt;head&gt;
&lt;title&gt;Hello&lt;/title&gt;
&lt;/head&gt;</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>produce this output:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Hello&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
World
&lt;/body&gt;
&lt;/html&gt;</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<br clear="all">
</td>
</tr>
</table>
</td>
</tr>
<!-- FOOTER SEPARATOR -->
<tr>
<td colspan="2">
<hr noshade="" size="1"/>
</td>
</tr>
<!-- PAGE FOOTER -->
<tr><td colspan="2">
<div align="center"><font color="#525D76" size="-1"><em>
Copyright &#169; 1999-2003, Apache Software Foundation
</em></font></div>
</td></tr>
</table>
</body>
</html>