Home arrow JavaScript arrow Page 2 - Validators: Concluding Remarks

Validators: Concluding Remarks

This article discusses two facets of the Struts-Validation framework. The first one deals with complex rules, while the second concerns information for creating custom rules that could be hooked up with the Validation framework.

Author Info:
By: A.P.Rajshekhar
Rating: 5 stars5 stars5 stars5 stars5 stars / 14
September 28, 2005
  1. · Validators: Concluding Remarks
  2. · Creating Custom Validators
  3. · Define the validation logic
  4. · Create an entry in the Validator-rules.xml

print this article

Validators: Concluding Remarks - Creating Custom Validators
(Page 2 of 4 )

Though the Validator framework provides most of the rules, there will be times when a custom rule (which even validwhen wouldn’t satisfy) must be applied. In such circumstances, there are two possible approaches. The first one involves writing JavaScript to apply the rule. But in this case the same trouble raises its head -- the problem of reuse.

The other approach follows the path of the Validator framework. This ensures reuse of the rule without embedding the JavaScript explicitly by the web designer. As an example I will be using the registration page itself. There is a field for phone number entry. The required rule is that the entered number has to follow a certain pattern. Though this is possible through the mask Validator, I decided to go ahead with creating a custom rule, as it would also help in experimenting with the Validator framework. So let's see how it is done, without much ado.

To create a custom Validator, certain steps must be followed.

First, you need to create a Java class that will contain the validation logic.  This is the basis of it all. The class would contain only one method. The method must be static, so that the framework can call it without having to create an object.

The class I have created is as follows:

public class PhoneRules

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