|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.velocity.tools.generic.RenderTool org.apache.velocity.tools.view.tools.ViewRenderTool
This tool expose methods to evaluate the given
strings as VTL (Velocity Template Language)
and automatically using the current context.
Example of eval(): Input ----- #set( $list = [1,2,3] ) #set( $object = '$list' ) #set( $method = 'size()' ) $render.eval("${object}.$method") Output ------ 3 Example of recurse(): Input ----- #macro( say_hi )hello world!#end #set( $foo = '#say_hi()' ) #set( $bar = '$foo' ) $render.recurse('$bar') Output ------ hello world! Toolbox configuration: <tool> <key>render</key> <scope>request</scope> <class>org.apache.velocity.tools.view.tools.ViewRenderTool</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 NOT meant to be used in either application or session scopes of a servlet environment.
Field Summary | |
private org.apache.velocity.context.Context |
context
|
Fields inherited from class org.apache.velocity.tools.generic.RenderTool |
|
Constructor Summary | |
ViewRenderTool()
Constructs a new instance |
Method Summary | |
java.lang.String |
eval(java.lang.String vtl)
Evaluates a String containing VTL using the current context, and returns the result as a String. |
void |
init(java.lang.Object obj)
Initializes this instance. |
java.lang.String |
recurse(java.lang.String vtl)
Recursively evaluates a String containing VTL using the current context, and returns the result as a String. |
Methods inherited from class org.apache.velocity.tools.generic.RenderTool |
eval, recurse |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private org.apache.velocity.context.Context context
Constructor Detail |
public ViewRenderTool()
Method Detail |
public void init(java.lang.Object obj)
init
in interface ViewTool
obj
- the current Contextpublic java.lang.String eval(java.lang.String vtl) throws java.lang.Exception
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.
vtl
- the code to be evaluated
java.lang.Exception
public java.lang.String recurse(java.lang.String vtl) throws java.lang.Exception
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.
TODO? add a parse-depth to prevent infinite recursion?
vtl
- the code to be evaluated
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |