Constants Rules in Validator Framework

Constants Rules in Validator Framework

Previous Home Next

 

The validator framework in struts allow you to define constant the can be used elsewhere in the fileYou want to define the global constant in the global area.

 First ,You want to define the global constant in the global tag area. FormSet/Locale constants can be created in the formset tags.

Constants only replaced in the Field's property attribute, the Field's var element value attribute, the Field's msg element key attribute, and Field's arg element's key attribute.

Example :-

struts-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE form-validation PUBLIC    
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"        
"http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">
<form-validation>
<global>
<constant> 
<constant-name>telephoneFormat</constant-name>
<constant-value>^\d{5,10}$</constant-value> 
</constant>
</global>
<formset>  
<form name="UserForm">  
<field property="name" depends="required"> 
<arg key="user.name" />
</field>
<field property="telephone" depends="required, mask">
<arg key="user.telephone" /> 
<arg1 key="user.telephone" />
<var>
<var-name>mask</var-name>   
<var-value>${telephoneFormat}</var-value>  
</var>   
</field>
<field property="usreemail" depends="email">
<arg0 key="user.email" />
<arg1 key="user.email" />
</field> 
</form>
</formset>
</form-validation>     

where constant-name attributes  is specified name of the constant property or constant-value attributes is specified value of the constant property.

Previous Home Next