Home arrow JavaScript arrow Page 2 - Validators: Concluding Remarks
JAVASCRIPT

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: 4 stars4 stars4 stars4 stars4 stars / 9
September 28, 2005
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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
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 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials