February 2005
Intermediate to advanced
528 pages
12h 53m
English
You want to define, in one place, a common value you can reference wherever needed in a Validator form.
Define the value as a global or form-set constant in one of your validation documents, as shown in Example 8-3.
Example 8-3. Defining global and form-set validator constants
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.1//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
<form-validation>
<global>
<constant>
<constant-name>globalVarName</constant-name>
<constant-value>globalVarValue</constant-value>
</constant>
</global>
<formset>
<constant>
<constant-name>formsetVarName</constant-name>
<constant-value>formsetVarValue</constant-value>
</constant>
<form name="MyForm">
<field property="myfield"
depends="someRule,anotherRule">
<var>
<var-name>someRule</var-name>
<var-value>${globalVarName}</var-value>
</var>
<var>
<var-name>anotherRule</var-name>
<var-value>${formsetVarName}</var-value>
</var>
</field>
</form>
<formset>
<form-validation>Good developers understand the
Don't Repeat Yourself
(DRY) principle of software engineering. But if they fail to follow
this principle, they could end up all wet. The Validator embraces
this guideline, making it an excellent choice for input validation.
If you have an attribute value shared by multiple
field elements, you can define the value as a named constant. ...