• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Limits of Validator Framework

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose i want to check either name or SSN field is specified. How can i check this using validator framework?

validwhen also has the limitations..
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If all you want to do is check that either field is entered, that can be done quite easliy with the validwhen validation rule. Example:


You're right, though, about the fact that validwhen has some serious limitations. In this example, if you not only wanted to check that either name or SSN is entered, but also that the SSN if entered contains only digits, validwhen doesn't give you a way to do that. You'd have to write a custom validation rule.
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the easiest way is to override the validate() and call super.validate() from it.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"You'd have to write a custom validation rule"

Then why would I even need a Validator framework explicitly??
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's not lose sight of the fact that the validator framework was designed to handle only the simple validations. Example: is it non-blank? is it an integer? is it a valid email address?

Anything much more complicated than that requires you to write your own validation code. Example: Is the account number valid? Were at least three of the five checkboxes checked?

In answer to Jothi's question, there are a lot of good reasons for using the validation framework. The most obvious is that it provides a codeless way of performing simple validations. The fact that it also provides client-side validation is also a big plus.

In Sandeep's example, if this is a validation that occurs only once in your application, then I agree that it's easier just to put the logic in the validate() method. However, if the same validation is used multiple times in the application, it might be worth while to create a custom validation rule.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome replies Merril...Thanks once again!
reply
    Bookmark Topic Watch Topic
  • New Topic