The Jakarta Project < Tools - View >

Velocity Tools

VelocityView

VelocityView Tools

Other Subprojects

ViewRenderTool Reference Documentation
       

This tool exposes methods to evaluate the given strings as VTL (Velocity Template Language) and automatically using the current context.

Class
 org.apache.velocity.tools.view.tools.ViewRenderTool
Name
 $render (this is the recommended name of the tool in the Velocity context)
Toolbox Configuration Example
 
<tool>
  <key>render</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.view.tools.ViewRenderTool</class>
</tool>
Author(s)
 Nathan Bubna
Method Overview
eval() Evaluates a String containing VTL using the current context, and returns the result as a String.
recurse() Recursively evaluates a String containing VTL using the current context, and returns the result as a String.
eval()
       

Evaluates a String containing VTL using the current context, and returns the result as a String.

String eval(String vtl)

Parameters
vtl
The code to be evaluated.
Returns
The evaluated code as a String.

Evaluates a String containing VTL using the current context, and returns the result as a String. If this fails, then null will be returned. This evaluation is not recursive.

#set( $list = [1,2,3] )
#set( $object = '$list' )
#set( $method = 'size()' )
$render.eval("${object}.$method")

This will produce the following output:

3

recurse()
       

Recursively evaluates a String containing VTL using the current context, and returns the result as a String.

String recurse(String vtl)

Parameters
vtl
The code to be evaluated.
Returns
The evaluated code as a String

Recursively evaluates a String containing VTL using the current 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.

#macro( say_hi )hello world!#end
#set( $foo = '#say_hi()' )
#set( $bar = '$foo' )
$render.recurse('$bar')

This will produce the following output:

hello world!


Copyright © 1999-2003, Apache Software Foundation