The Jakarta Project < Tools - View >

Velocity Tools

VelocityView

VelocityView Tools

その他のサブプロジェクト

ViewRenderTool リファレンスドキュメント
       

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

与えられた文字列をVTL(Velocity テンプレート言語)として評価するメソッドを提供するツールです。 その際、自動的にカレントコンテキストを使用します。

Class
 org.apache.velocity.tools.view.tools.ViewRenderTool
Name
 $render (Velocityコンテキスト内での推奨名)
Toolbox設定例
 
<tool>
  <key>render</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.view.tools.ViewRenderTool</class>
</tool>
作者
 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.
Method Overview
eval() カレントコンテキストを使用してVTLを含めた文字列を評価し、 結果を文字列として返却します。
recurse() カレントコンテキストを使用してVTLを含めた文字列を再起的に評価し、 結果を文字列として返却します。
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

カレントコンテキストを使用してVTLを含めた文字列を評価し、 結果を文字列として返却します。

String eval(String vtl)

Parameters
vtl
評価対象のコード。
Returns
コードを評価した結果の文字列。

カレントコンテキストを使用してVTLを含めた文字列を評価し、 結果を文字列として返却します。失敗した場合、null が返却されます。この評価は再起的ではありません。

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

これは以下の出力を生成します:

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!

カレントコンテキストを使用してVTLを含めた文字列を再起的に評価し、 結果を文字列として返却します。

String recurse(String vtl)

Parameters
vtl
評価対象のコード。
Returns
コードを評価した結果の文字列。

カレントコンテキストを使用してVTLを含めた文字列を再起的に評価し、 結果を文字列として返却します。 評価の結果が評価前のコードと同じになるまで直前の結果を繰り返し評価します。

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

これは以下の出力を生成します:

hello world!


[訳注: この文書は Shinobu Kawai 木村 貴由 が翻訳しました。 日本語訳に対するコメントがあれば、report@jajakarta.orgに送って下さい。]
Copyright © 1999-2003, Apache Software Foundation