The Jakarta Project < Velocity Tools - Struts >

Velocity Tools

VelocityStruts

VelocityStruts Tools

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

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

The ValidatorTool is used to interact with the Validator framework to generate dynamic javascript for form validation.

ValidatorToolはValidatorフレームワークと連携してフォームバリデーション用の動的javascriptを生成するために使用されます。

Class
 org.apache.velocity.tools.struts.ValidatorTool
Name
 $validator (Velocityコンテキスト内での推奨名)
Toolbox設定例
 
<tool>
  <key>validator</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.struts.ValidatorTool</class>
</tool>
作者
 Marino A. Jonsson
Method Overview
getPage() Gets the current page number of a multi-part form.
setPage() Sets the current page number of a multi-part form.
getMethod() Gets the method name that will be used for the javascript validation method name if it has a value.
setMethod() Sets the method name that will be used for the javascript validation method name if it has a value.
getHtmlComment() Gets whether or not to delimit the javascript with html comments.
setHtmlComment() Sets whether or not to delimit the javascript with html comments.
getSrc() Gets the src attribute's value when defining the html script element.
setSrc() Sets the src attribute's value (used to include an external script resource) when defining the html script element.
getCdata() Returns the cdata setting "true" or "false".
setCdata() Sets the cdata status.
getJavascript() Generates javascript to perform validations on a struts-defined form.
getDynamicJavascript() Generates the dynamic javascript methods to perform validation on a struts-defined form.
getStaticJavascript() Generates all the static javascript methods from validator-rules.xml.
Method Overview
getPage() マルチパートフォームの現在のページ番号を取得します。
setPage() マルチパートフォームの現在のページ番号を設定します。
getMethod() このメソッドが値を返却する場合、バリデーションを行うjavascriptのメソッド名として使われます。
setMethod() このメソッドに値を設定した場合、バリデーションを行うjavascriptのメソッド名として使われます。
getHtmlComment() javascriptをhtmlコメントで囲むかどうかを取得します。
setHtmlComment() javascriptをhtmlコメントで囲むかどうかを設定します。
getSrc() htmlのscript要素を定義する時のsrc属性の値を取得します。
setSrc() htmlのscript要素を定義する時のsrc属性の値を設定します。 これは外部スクリプトリソースを指定する時に使用します。
getCdata() cdataの設定"true"または"false"を返却します。
setCdata() cdataステータスを設定します。
getJavascript() strutsで定義されたフォームのバリデーションを行うjavascriptを生成します。
getDynamicJavascript() strutsで定義されたフォームのバリデーションを行う動的javascriptを生成します。
getStaticJavascript() validator-rules.xmlからすべての静的javascriptメソッドを生成します。
getPage()
       

Gets the current page number of a multi-part form.

int getPage()

Gets the current page number of a multi-part form. Only field validations with a matching page number will be generated that match the current page number.


マルチパートフォームの現在のページ番号を取得します。

int getPage()

マルチパートフォームの現在のページ番号を取得します。 現在のページ番号と同じページ番号を持つフィールドのみのバリデーションが生成されます。


setPage()
       

Sets the current page number of a multi-part form.

void setPage(int page)

Parameters
page
the current page number of a multi-part form.

Sets the current page number of a multi-part form. Only field validations with a matching page number will be generated that match the current page number.


マルチパートフォームの現在のページ番号を設定します。

void setPage(int page)

Parameters
page
マルチパートフォームの現在のページ番号。

マルチパートフォームの現在のページ番号を設定します。 現在のページ番号と同じページ番号を持つフィールドのみのバリデーションが生成されます。


getMethod()
       

Gets the method name that will be used for the javascript validation method name if it has a value.

String getMethod()

Gets the method name that will be used for the javascript validation method name if it has a value. This overrides the auto-generated method name based on the key (form name) passed in.


このメソッドが値を返却する場合、バリデーションを行うjavascriptのメソッド名として使われます。

String getMethod()

このメソッドが値を返却する場合、バリデーションを行うjavascriptのメソッド名として使われます。 これは与えられたキー(フォーム名)から自動生成されるメソッド名をオーバーライドします。


setMethod()
       

Sets the method name that will be used for the javascript validation method name if it has a value.

void setMethod(String methodName)

Parameters
methodName
the method name that will be used for the javascript validation method name.

Sets the method name that will be used for the javascript validation method name if it has a value. This overrides the auto-generated method name based on the key (form name) passed in.


このメソッドに値を設定した場合、バリデーションを行うjavascriptのメソッド名として使われます。

void setMethod(String methodName)

Parameters
methodName
バリデーションjavascriptのメソッド名

このメソッドに値を設定した場合、バリデーションを行うjavascriptのメソッド名として使われます。 これは与えられたキー(フォーム名)から自動生成されるメソッド名をオーバーライドします。


getHtmlComment()
       

Gets whether or not to delimit the javascript with html comments.

boolean getHtmlComment()

Gets whether or not to delimit the javascript with html comments. If this is set to 'true', which is the default, html comments will surround the javascript.


javascriptをhtmlコメントで囲むかどうかを取得します。

boolean getHtmlComment()

javascriptをhtmlコメントで囲むかどうかを取得します。 'true'(デフォルト)の場合、javascriptはhtmlコメントで囲まれます。


setHtmlComment()
       

Sets whether or not to delimit the javascript with html comments.

void setHtmlComment(boolean htmlComment)

Parameters
htmlComment
whether or not to delimit the javascript with html comments.

Sets whether or not to delimit the javascript with html comments. If this is set to 'true', which is the default, html comments will surround the javascript.


javascriptをhtmlコメントで囲むかどうかを設定します。

void setHtmlComment(boolean htmlComment)

Parameters
htmlComment
javascriptをhtmlコメントで囲むかどうか。

javascriptをhtmlコメントで囲むかどうかを設定します。 'true'(デフォルト)の場合、javascriptはhtmlコメントで囲まれます。


getSrc()
       

Gets the src attribute's value when defining the html script element.

String getSrc()

Gets the src attribute's value when defining the html script element.


htmlのscript要素を定義する時のsrc属性の値を取得します。

String getSrc()

htmlのscript要素を定義する時のsrc属性の値を取得します。


setSrc()
       

Sets the src attribute's value (used to include an external script resource) when defining the html script element.

void setSrc(String src)

Parameters
src
the src attribute's value.

Sets the src attribute's value (used to include an external script resource) when defining the html script element.


htmlのscript要素を定義する時のsrc属性の値を設定します。 これは外部スクリプトリソースを指定する時に使用します。

void setSrc(String src)

Parameters
src
src属性の値。

htmlのscript要素を定義する時のsrc属性の値を設定します。 これは外部スクリプトリソースを指定する時に使用します。


getCdata()
       

Returns the cdata setting "true" or "false".

boolean getCdata()

Returns the cdata setting "true" or "false".


cdataの設定"true"または"false"を返却します。

boolean getCdata()

cdataの設定"true"または"false"を返却します。


setCdata()
       

Sets the cdata status.

void setCdata(boolean cdata)

Parameters
cdata
The cdata to set

Sets the cdata status.


cdataステータスを設定します。

void setCdata(boolean cdata)

Parameters
cdata
設定するcdata

cdataステータスを設定します。


getJavascript()
       

Generates javascript to perform validations on a struts-defined form.

String getJavascript()

String getJavascript(String formName)

Parameters
formName
The name of a struts-defined form.

Generates both dynamic and static javascript to perform validations on a struts-defined form. By default it uses the form associated with the action. A form name can also be supplied as a parameter to generate javascript for a struts-defined form that is not associated with this particular action.

Assuming that the name of a form associated with a given action is myForm, the following Velocity script:

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

$validator.getJavascript()

produces something like this output (heavily abbreviated):

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

<script type="text/javascript" language="Javascript1.1">
<!-- Begin

var bCancel = false;

function validateMyForm(form) {
	// call the relevant static methods to validate this form
	...
}

// some more dynamic functions dependent on which validations to perform.
...
...

// finally come all the static validator methods defined in validator-rules.xml
...
...

//End -->
</script>

strutsで定義されたフォームのバリデーションを行うjavascriptを生成します。

String getJavascript()

String getJavascript(String formName)

Parameters
formName
strutsで定義されたフォームの名前。

strutsで定義されたフォームのバリデーションを行う動的、 静的両方のjavascriptを生成します。 デフォルトではアクションと関連付けられたフォームを使用します。 フォーム名を与えることによって、 このアクションと関連付けられていないフォームのためのjavascriptを生成することもできます。

アクションと関連付けられたフォーム名がmyFormとして、 次のVelocityスクリプト:

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

$validator.getJavascript()

は以下のような出力を生成します(かなり短縮されています):

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

<script type="text/javascript" language="Javascript1.1">
<!-- Begin

var bCancel = false;

function validateMyForm(form) {
	// フォームのバリデーションに必要な静的メソッドを呼び出します
	...
}

// どのバリデーションを行うかに依存する動的function。
...
...

// 最後に、validator-rules.xmlに定義されたバリデーションの静的メソッドが来ます。
...
...

//End -->
</script>

getDynamicJavascript()
       

Generates the dynamic javascript methods to perform validation on a struts-defined form.

String getDynamicJavascript()

String getDynamicJavascript(String formName)

Parameters
formName
The name of a struts-defined form.

Generates the dynamic javascript to perform validations on a struts-defined form. By default it uses the form associated with the action. A form name can also be supplied as a parameter to generate javascript for a struts-defined form that is not associated with this particular action. This method does not work by itself - it requires that the relevant static methods be accessible i.e. in a seperate .js file.

Assuming that the name of a form associated with a given action is myForm, the following Velocity script:

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

$validator.getDynamicJavascript()

produces something like this output (heavily abbreviated):

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

<script type="text/javascript" language="Javascript1.1">
<!-- Begin

var bCancel = false;

function validateMyForm(form) {
	// call the relevant static methods to validate this form
	...
}

// some more dynamic functions dependent on which validations to perform.
...
...

//End -->
</script>

strutsで定義されたフォームのバリデーションを行う動的javascriptを生成します。

String getDynamicJavascript()

String getDynamicJavascript(String formName)

Parameters
formName
strutsで定義されたフォームの名前。

strutsで定義されたフォームのバリデーションを行う動的javascriptを生成します。 デフォルトではアクションと関連付けられたフォームを使用します。 フォーム名を与えることによって、 このアクションと関連付けられていないフォームのためのjavascriptを生成することもできます。 このメソッドが単独では動きません。 必要な静的メソッドがアクセスできること(i.e. 別の.jsファイルにて)を要求します。

アクションと関連付けられたフォーム名がmyFormとして、 次のVelocityスクリプト:

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

$validator.getDynamicJavascript()

は以下のような出力を生成します(かなり短縮されています):

<form action="/someAction.do" onsubmit="return validateMyForm(this)">
...
...
</form>

<script type="text/javascript" language="Javascript1.1">
<!-- Begin

var bCancel = false;

function validateMyForm(form) {
	// フォームのバリデーションに必要な静的メソッドを呼び出します
	...
}

// どのバリデーションを行うかに依存する動的function。
...
...

//End -->
</script>

getStaticJavascript()
       

Generates all the static javascript methods from validator-rules.xml.

String getStaticJavascript()

Generates the static javascript methods from validator-rules.xml to perform validations on a any form. Useful i.e. if the static methods should be located in a seperate .js file.

The following Velocity script:

$validator.getStaticJavascript()

produces something like this output (heavily abbreviated):

<script type="text/javascript" language="Javascript1.1">
<!-- Begin

function validateFloatRange(form) {
	...
    	...
}

function validateByte(form) {
	...
    	...
}

// and a bunch more ...
...

//End -->
</script>

validator-rules.xmlからすべての静的javascriptメソッドを生成します。

String getStaticJavascript()

どのフォームに対してもバリデーションを行えるよう、 validator-rules.xmlからすべての静的javascriptメソッドを生成します。 静的メソッドが別の.jsファイルに置かれるべき場合に便利です。

次のVelocityスクリプト:

$validator.getStaticJavascript()

は以下のような出力を生成します(かなり短縮されています):

<script type="text/javascript" language="Javascript1.1">
<!-- Begin

function validateFloatRange(form) {
	...
    	...
}

function validateByte(form) {
	...
    	...
}

// そしてもっとたくさん ...
...

//End -->
</script>


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