Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Limits of Validator Framework

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • 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..
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Actually the easiest way is to override the validate() and call super.validate() from it.
 
Joe Harry
Ranch Hand
Posts: 10105
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 Harry
Ranch Hand
Posts: 10105
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome replies Merril...Thanks once again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic