commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Arun Thomas" <Arun.Tho...@solidusnetworks.com>
Subject RE: jakarta-commons/validator General Question
Date Mon, 19 May 2003 21:33:50 GMT
1) Agree that the static methods on GenericValidator can be called directly - but only for
programmatic validations - none of them are actually usefully invokable by the validator framework.
 According to the rules of the framework, the object to be validated should always be added
to the Validator with the Validator.BEAN_KEY which is defined as java.lang.Object.  If the
method signature of the validation function does not have java.lang.Object as the type of
one of it's arguments, this object will never be passed to the validation function.  Most
of the validation function in GenericValidator do not have java.lang.Object as an argument.
 

Here's the relevant code from Validator.java which sets up the method parameters and values
for invoking the validation function:

            for (int x = 0; x < size; x++) {
                String paramKey = (String) lParams.get(x);

                if (BEAN_KEY.equals(paramKey)) { 
                    beanIndexPos = x;            
                }                                

                if (FIELD_KEY.equals(paramKey)) {
                    fieldIndexPos = x;
                }

                // There were problems calling getClass on paramValue[]
                paramClass[x] = getClassLoader().loadClass(paramKey);

                paramValue[x] = hResources.get(paramKey);
            }

As you can see from this, it's not even possible to use validation functions which have primitive
arguments as validation functions - getClassLoader().loadClass(paramKey) should fail with
a ClassNotFoundException. 

In short, GenericValidator is a bad name for that class - since it acts pretty much as a utility
class providing functions that may be used by the actual validation functions called by the
validator following a delegation model.  It is not, as the name implies, a validator of itself,
nor is it even directly usable by the validator framework.  

2) I agree completely with your comment as follows: "So, you can validate an entire bean by
defining the validations to be passed by its individual properties.  The framework allows
you to pass in the whole bean to be validated instead of 
requiring you to pass in each field."  I don't agree that validation "...requires you to define
validations per property".  

First, let me make sure that we're on the same page when we speak about a "validation".  For
me, I'm using the term validation to refer to one method call by the validator framework,
with the bean/form to be validated as an argument.  That said, one validation can check the
values individually or collectively, of as many properties as desired on the bean.  If more
than one property is actually checked by this one method call, is this a "field" validation,
or a "fields" validation (better labeled a "bean/form" validation)?  I don't think that validation
- in the sense of a method to call - should need to be defined for every property.  It should
be perfectly acceptable to have validations which check multiple properties.  (In fact, the
current design supports this just fine - it's just that the name "field validation" suggests
that it isn't supported.)  

Cheers, 
-AMT	
 

-----Original Message-----
From: David Graham [mailto:dgraham1980@hotmail.com] 
Sent: Monday, May 19, 2003 11:35 AM
To: commons-dev@jakarta.apache.org
Subject: RE: jakarta-commons/validator General Question


You can call the static methods in GenericValidator directly.

The reason it's called "field validations" is because you're applying a 
specific set of validations to a field.  So, you can validate an entire bean 
by defining the validations to be passed by its individual properties.  The 
framework allows you to pass in the whole bean to be validated instead of 
requiring you to pass in each field.

I agree with you that validator should be bean focused and not field focused 
but even this requires you to define validations per property.

David

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message