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

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 / 14
September 13, 2005
  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

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


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:




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.

       <arg0 key="registrationForm.zippostal.displayname"/>

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.


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"/>



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

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


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