<html> | |
<head> | |
<title>Velocity - RenderTool</title> | |
<meta name="author" value="Shinobu Kawai"/> | |
<meta name="email" value="shinobu.kawai@gmail.com" /> | |
</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/velocitygenerictools.png" align="right" alt="< Velocity Tools - Library >" 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>Generic Tools</strong> | |
</p> | |
<ul> | |
<li><a href="index.html">Overview</a></li> | |
<li><a href="../index.html#Download">Download</a></li> | |
<li><a href="index.html#Contributions">Contributions</a></li> | |
<li><a href="../javadoc/index.html">Javadoc</a></li> | |
</ul> | |
<p> | |
<strong>Tool Documentation</strong> | |
</p> | |
<ul> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/DateTool.html">DateTool</a></li> | |
<li><a href="MathTool.html">MathTool</a></li> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/NumberTool.html">NumberTool</a></li> | |
<li><a href="RenderTool.html">RenderTool</a></li> | |
<li><a href="EscapeTool.html">EscapeTool</a></li> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/Alternator.html">Alternator</a></li> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/AlternatorTool.html">AlternatorTool</a></li> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/ValueParser.html">ValueParser</a></li> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/ListTool.html">ListTool</a></li> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/SortTool.html">SortTool</a></li> | |
<li><a href="../javadoc/org/apache/velocity/tools/generic/IteratorTool.html">IteratorTool</a></li> | |
</ul> | |
<p> | |
<strong>Other Subprojects</strong> | |
</p> | |
<ul> | |
<li><a href="../view/">VelocityView</a></li> | |
<li><a href="../struts/">VelocityStruts</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="RenderTool Reference Documentation"> | |
<strong>RenderTool Reference Documentation</strong></a></font> | |
</td> | |
</tr> | |
<tr> | |
<td NOWRAP> </td> | |
<td> | |
<p>This tool exposes methods to evaluate the given strings as VTL | |
(Velocity Template Language) and automatically using the current context.</p> | |
<table cellpadding="0" cellspacing="0"> | |
<tr><td colspan="2"><strong>Class</strong></td></tr> | |
<tr><td> </td><td>org.apache.velocity.tools.generic.RenderTool</td></tr> | |
<tr><td colspan="2"><strong>Name</strong></td></tr> | |
<tr><td> </td><td>$render (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> </td><td><pre><tool> | |
<key>render</key> | |
<scope>application</scope> | |
<class>org.apache.velocity.tools.generic.RenderTool</class> | |
</tool></pre></td></tr> | |
<tr><td colspan="2"><strong>Author(s)</strong></td></tr> | |
<tr><td> </td><td><a href="mailto:nathan@esha.com">Nathan Bubna</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="#eval()">eval()</a></td> | |
<td bgcolor="EEEEEE"> | |
Evaluates a String containing VTL using the current context, and | |
returns the result as a String. | |
</td> | |
</tr> | |
<tr> | |
<td bgcolor="EEEEEE" nowrap> | |
<a href="#recurse()">recurse()</a></td> | |
<td bgcolor="EEEEEE"> | |
Recursively evaluates a String containing VTL using the | |
current context, and returns the result as a String. | |
</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="eval()"> | |
<strong>eval()</strong></a></font> | |
</td> | |
</tr> | |
<tr> | |
<td NOWRAP> </td> | |
<td> | |
<p> | |
<abstract> | |
Evaluates a String containing VTL using the current context, and | |
returns the result as a String. | |
</abstract> | |
</p> | |
<p> | |
<table width="100%"><tr><td bgcolor="EEEEEE"> | |
<font size="+1"><code> | |
<signature> | |
String eval(Context ctx, String vtl) | |
</signature> | |
</code></font> | |
</td></tr></table> | |
</p> | |
<dl> | |
<dt><strong>Parameters</strong></dt> | |
<dd> | |
<dl> | |
<dt>ctx</dt> | |
<dd> | |
<parameter name="ctx"> | |
The Context to be evaluate the vtl with. | |
</parameter> | |
</dd> | |
<dt>vtl</dt> | |
<dd> | |
<parameter name="vtl"> | |
The code to be evaluated. | |
</parameter> | |
</dd> | |
</dl> | |
</dd> | |
</dl> | |
<dl> | |
<dt><strong>Returns</strong></dt> | |
<dd> | |
<returns> | |
The evaluated code as a String. | |
</returns> | |
</dd> | |
</dl> | |
<p>Evaluates a String containing VTL using the given context, and | |
returns the result as a String. If this fails, then <code>null</code> | |
will be returned. This evaluation is not recursive.</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>#set( $list = [1,2,3] ) | |
#set( $object = '$list' ) | |
#set( $method = 'size()' ) | |
$render.eval($ctx, "${object}.$method")</sourcecode></pre> | |
</td></tr></table> | |
</td></tr></table> | |
<p>This will produce the following 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>3</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="recurse()"> | |
<strong>recurse()</strong></a></font> | |
</td> | |
</tr> | |
<tr> | |
<td NOWRAP> </td> | |
<td> | |
<p> | |
<abstract> | |
Recursively evaluates a String containing VTL using the | |
current context, and returns the result as a String. | |
</abstract> | |
</p> | |
<p> | |
<table width="100%"><tr><td bgcolor="EEEEEE"> | |
<font size="+1"><code> | |
<signature> | |
String recurse(Context ctx, String vtl) | |
</signature> | |
</code></font> | |
</td></tr></table> | |
</p> | |
<dl> | |
<dt><strong>Parameters</strong></dt> | |
<dd> | |
<dl> | |
<dt>vtl</dt> | |
<dd> | |
<parameter name="vtl"> | |
The code to be evaluated. | |
</parameter> | |
</dd> | |
<dt>ctx</dt> | |
<dd> | |
<parameter name="ctx"> | |
The Context to be evaluate the vtl with. | |
</parameter> | |
</dd> | |
</dl> | |
</dd> | |
</dl> | |
<dl> | |
<dt><strong>Returns</strong></dt> | |
<dd> | |
<returns> | |
The evaluated code as a String. | |
</returns> | |
</dd> | |
</dl> | |
<p>Recursively evaluates a String containing VTL using the | |
given context, and returns the result as a String. It | |
will continue to re-evaluate the output of the last | |
evaluation until an evaluation returns the same code | |
that was fed into it.</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>#macro( say_hi )hello world!#end | |
#set( $foo = '#say_hi()' ) | |
#set( $bar = '$foo' ) | |
$render.recurse($ctx, '$bar')</sourcecode></pre> | |
</td></tr></table> | |
</td></tr></table> | |
<p>This will produce the following 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>hello world!</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 © 1999-2003, Apache Software Foundation | |
</em></font></div> | |
</td></tr> | |
</table> | |
</body> | |
</html> |