Validation

The OJB Console is fully integrated with the Struts Validation and the Commons Validator. You can leverage the Struts validator to associate specific validations with the Insert/Edit for of any class. Follow the following steps to learn how this is done:

Please see the Struts documentation for more information on the validations.

Update WEB-INF/validation.xml

The only thing required to utilize your own validations is to add your validation configuration as you would normally do for a struts application to the validation.xml under src/web/WEB-INF. You only need to make the following adjustments: Note:
  • Currently, only server-side validations are supported.
  • Only one argument is supported, this is the attribute name.

    The following example demonstrates a struts validation.xml

    <form-validation>
       <global>   
         <constant>
            <constant-name>zip</constant-name>
            <constant-value>^\d{5}(-\d{4})?$</constant-value>
         </constant>         	            	   
       </global>
       
       <formset>     
          <form name="org.scrashmeow.ojb.content.Address">
             <field 
               property="shippingAddress"
               depends="required,mask">
               <arg0 key="label.address"/>
               <var>
                 <var-name>mask</var-name>
                 <var-value>^[\w\s]+$</var-value>
               </var>
             </field>         
             <field 
               property="shippingCity"
               depends="required,mask">
               <arg0 key="label.city"/>           
               <var>
                 <var-name>mask</var-name>
                 <var-value>^[a-zA-Z]*$</var-value>
               </var>
             </field>         
             <field 
               property="shippingState"
               depends="required,mask">
               <arg0 key="label.state"/>
               <var>
    	     <var-name>mask</var-name>
    	     <var-value>^[a-zA-Z]*$</var-value>
               </var>
             </field>         
             <field 
               property="shippingPostal"
               depends="required,mask">
               <arg0 key="label.postalCode"/>
               <arg1 name="minlength" key="${var:minlength}" resource="false"/>
               <var>
                 <var-name>mask</var-name>
                 <var-value>${zip}</var-value>
               </var>         	   
             </field>
          </form>            
       </formset>   
      
    </form-validation>
    
    Here is the repository.xml configuration for this same class:
    
    
    <class-descriptor class="org.scrashmeow.ojb.content.Address" table="ADDRESSES">
    	<field-descriptor name="uid" column="UID" jdbc-type="VARCHAR" primarykey="true"  nullable="false" />
    	<field-descriptor name="shippingAddress" column="ADDRESS" jdbc-type="VARCHAR" nullable="false" />
    	<field-descriptor name="shippingCity" column="CITY" jdbc-type="VARCHAR" nullable="false" />
    	<field-descriptor name="shippingState" column="STATE" jdbc-type="VARCHAR" nullable="false" />
    	<field-descriptor name="shippingPostal" column="POSTAL" jdbc-type="VARCHAR" nullable="false" />
    </class-descriptor>
    
    

    Copyright © 2003 Alexander Bibighaus et al. All rights Reserved.