ViewRenderTool Reference Documentation

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

@@@version@@@, @@@date@@@org.apache.velocity.tools.view.tools.ViewRenderTool$renderNathan Bubna<tool> <key>render</key> <scope>request</scope> <class>org.apache.velocity.tools.view.tools.ViewRenderTool</class> </tool>The Javadoc for more info.

eval()

Evaluates a String containing VTL using the current context, and returns the result as a String. String eval(String vtl) The code to be evaluated. 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) The code to be evaluated. 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!