|
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>
|
|
|