Home arrow JavaScript arrow Page 3 - Validators: Into the Deep
JAVASCRIPT

Validators: Into the Deep


In the first part, we saw a glimpse of what the Validator framework can do. But that is just the tip of the iceberg. The driving force behind creation of the Validator framework is reusability. This facet of the framework is but one of the many aspects that can not only reduce the web GUI development time but also enforce standards across all interfaces.

Author Info:
By: A.P.Rajshekhar
Rating: 5 stars5 stars5 stars5 stars5 stars / 11
September 13, 2005
TABLE OF CONTENTS:
  1. · Validators: Into the Deep
  2. · Email, Mask, Date, and Length Validators
  3. · Constants and Variables
  4. · Registration Form: Putting it All Together

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Validators: Into the Deep - Constants and Variables
(Page 3 of 4 )

Constants

Reusability is the core of the Validator framework. So it is unthinkable that there wouldn’t be a way to reuse the rules. The approach provided by the framework is in the form of constants. A constant is a rule defined in the <global > tag that can be used to replace a Field's property attribute, the Field's <var> element value attribute, the Field's <msg> element key attribute, and the Field's arg0-arg3 element's key attributes. So whatever rules are set using the <constant> tag, they can be used to replace the same rule if it recurs. To make things clear, let's see an example:

 <global>
         <constant>

         <constant-name>zip</constant-name>
         <constant-value>^\d{5}(-\d{4})?$</constant-value>

         </constant>
 </global>

The constants are declared within the <constant> </constant> tag. The constants have to be given using the <constant-name> tag. Here the name is zip, as this constant is being used to check the zip value being entered. Next <constant-value> is used to specify the actual rule. Here the rule is a regular expression.


      <field
            property="zip"
            depends="required,mask">
       <arg0 key="registrationForm.zippostal.displayname"/>
        <var>
            <var-name>mask</var-name>
            <var-value>${zip}</var-value>
        </var>
       </field>


Then the constant can be used by its name as seen in the <var> node’s <var-value> element’s value. The evaluation of the constant is done using EL.

Variables

When variables must be passed to be used by a pluggable Validator, variables are used. Variables are specified by the <var> tag. An example would clarify it further:


<field property="name" depends="required,maxlength">
   <arg0 key="customer.name"/>
   <arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
       <var>

  <var-name>maxlength</var-name>
  <var-value>30</var-value>

    </var>
 </field>


The variable is declared and defined using the <var> tag. The first child node of <var> defines the name of the variable. Here the name of the variable is maxlength. Then the value to be used is specified using the <var-value> tag. Here the value is 30. The variable can be used as a value of the key attribute of field element.

In a nutshell, constants can be used to represent the rules that can become part of the <var-value>, whereas the variable can be used to provide the value of key attributes of <arg1> at runtime.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials