You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Hirsch Richard <ri...@siemens.com> on 2002/07/24 11:35:14 UTC

Global Field Definitions in validation.xml?

We have a large number of forms with similar fields (First Name, Last name,
etc.) We would like to use the validation framework from struts to validate
our fields. Is it possible to create global definitions for field types? I
have never seen a DTD for the validation.xml file format, so I am in the
dark regrading the possible elements in the global tag. I know "constants"
and "validator" are possible. 

We need an entire definition of a field type. Example below:

   <global>
      <constant>
        <field    property="firstname"
         	   depends="required,mask,minlength,maxlength">
         	     <arg0 key="form.surname"/>
         	     <arg1 name="minlength" key="${var:minlength}"
resource="false"/>
         	     <arg1 name="maxlength" key="${var:maxlength}"
resource="false"/>
                     <var>
                       <var-name>mask</var-name>
                       <var-value>^\w+$</var-value>
                     </var>
                     <var>
                       <var-name>minlength</var-name>
                       <var-value>5</var-value>
                     </var>
                     <var>
                       <var-name>maxlength</var-name>
                       <var-value>6</var-value>
                     </var>
         </field>  
      </constant>         	           	   
   </global>
   <formset>      	   
         <form    name="registerForm">
         <field    property="reg.firstname"
         	   uses="${firstname}">
         </field>
         ....    
      </form>
      <form    name="chPasswordForm">
         <field    property="password.firstname"
         	   uses="${firstname}">
         </field>
         ....
      </form>
   </formset>

That way changes to validation rules have global impact throughout the
application.

Thanks,

D.