This tool exposes methods to evaluate the given
strings as VTL (Velocity Template Language)
using the given context.
NOTE: These examples assume you have placed an
instance of the current context within itself
as 'ctx'. And, of course, the RenderTool is
assumed to be available as 'render'.
Example of eval():
Input
-----
#set( $list = [1,2,3] )
#set( $object = '$list' )
#set( $method = 'size()' )
$render.eval($ctx, "${object}.$method")
Output
------
3
Example of recurse():
Input
-----
#macro( say_hi )hello world!#end
#set( $foo = '#say_hi()' )
#set( $bar = '$foo' )
$render.recurse($ctx, $bar)
Output
------
hello world!
Toolbox configuration:
<tool>
<key>render</key>
<class>org.apache.velocity.tools.generic.RenderTool</class>
</tool>
Ok, so these examples are really lame. But, it seems like
someone out there is always asking how to do stuff like this
and we always tell them to write a tool. Now we can just tell
them to use this tool.
This tool is safe (and optimized) for use in the application
scope of a servlet environment.
author: Nathan Bubna version: $Revision: 484711 $ $Date: 2006-12-08 11:41:50 -0800 (Fri, 08 Dec 2006) $ |