Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 63382 invoked from network); 26 May 2004 17:16:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 26 May 2004 17:16:46 -0000 Received: (qmail 34990 invoked by uid 500); 26 May 2004 17:15:07 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 34341 invoked by uid 500); 26 May 2004 17:14:58 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 33905 invoked by uid 98); 26 May 2004 17:14:51 -0000 Received: from niall.pemberton@blueyonder.co.uk by hermes.apache.org by uid 82 with qmail-scanner-1.20 (clamuko: 0.70. Clear:RC:0(195.188.213.6):. Processed in 0.351743 secs); 26 May 2004 17:14:51 -0000 X-Qmail-Scanner-Mail-From: niall.pemberton@blueyonder.co.uk via hermes.apache.org X-Qmail-Scanner: 1.20 (Clear:RC:0(195.188.213.6):. Processed in 0.351743 secs) Received: from unknown (HELO smtp-out3.blueyonder.co.uk) (195.188.213.6) by hermes.apache.org with SMTP; 26 May 2004 17:14:50 -0000 Received: from DELL1800 ([82.43.172.127]) by smtp-out3.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.5600); Wed, 26 May 2004 18:14:25 +0100 Message-ID: <003301c44345$504e7520$7fac2b52@DELL1800> From: "Niall Pemberton" To: "Jakarta Commons Developers List" References: <20040526130733.71456.qmail@web50610.mail.yahoo.com> <40B4BEBD.30509@twdata.org> Subject: Re: [validator] Why doesn't commons-validator include functional validators? Date: Wed, 26 May 2004 18:17:25 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-OriginalArrivalTime: 26 May 2004 17:14:26.0000 (UTC) FILETIME=[E5798500:01C44344] X-Spam-Rating: hermes.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Personally I prefer the "facade" method. I like the fact that, for example, the UrlValidator only contains the logic to validate a url and knows nothing about the "validator" framework it sits in. I think this has two advantages: * Users could utilise the validation without having to adopt the framework - maybe embedding it in their "business logic" or an alternative framework. Some users (e.g. Edgar Dollin's recent message on the Struts Dev list) don't want to put their validation rules in an XML file. I don't think we should limit validator's use by forcing the adoption of the framework. * It's easier to test - writing test scripts is simpler, you don't have to have a whole load of XML set up to test the actual validation logic. The other thing I was thinking is that the method signitures are too simple...validations could return several things: true/false, a converted value, an error code, an error message - maybe all of these should be returned in a ValidatorResult object rather than just true/false. Also how about having a validator "context" object - in the Struts world if someone wanted to write a validator which accessed the Request, then they could provide it through the "context. public ValidatorResult isValid(Object bean, Field field, ValidatorAction va, Context context); Niall ----- Original Message ----- From: "Don Brown" To: "Jakarta Commons Developers List" Sent: Wednesday, May 26, 2004 4:58 PM Subject: Re: [validator] Why doesn't commons-validator include functional validators? > Yes, in my view, validator config should refer directly to the validator > being used. This makes the config more readable, IMO. I thought about > making a FieldChecks-type facade object for commons-validator, but the > adapter methods - i.e. isValid(Object bean, Field field) - still need to > be generated for each validator and I think it is cleaner to, when > adding a new validator or changing an existing, only have to modify one > file, the validator, rather than the validator and the facade. > > To help solve the duplication, I've created a SimpleValidator abstract > class that has two methods: > > public boolean isValid(Object bean, Field field); > public abstract boolean isValid(String val); > > For the simple validators, they could extend this class and only > implement the abstract method. I'm not sure what else one could do since > the limiting factor is the unique signatures of the actual validation > method. > > Don > > David Graham wrote: > > >--- Don Brown wrote: > > > > > >>Just to be clear, the approach I feel would be simplest is to add > >>"isValid(Object bean, Field field)"-type methods to each validator. This > >> > >>way, the validators commons-validator provides can be used as they are > >>or front-ended like how Struts' FieldChecks class interacts with them. > >> > >> > > > >So would you configure xml elements that reference > >DateValidator directly instead of FieldChecks? Would we be able to remove > >some of FieldChecks' methods? > > > > > > > > > >>I've already gone through several validators, adding unit tests as I go, > >> > >>and things are looking good. Before I finish the rest of the validators, > >> > >>however, I want to make sure this is a good idea in the eyes of everyone > >> > >>else. > >> > >>For example, the new DateValidator looks like this: > >> > >>public boolean isValid(Object bean, Field field); > >>public boolean isValid(Object bean, Field field, Locale locale); > >>public boolean isValid(String value, String datePattern, boolean > >>strict); > >>public boolean isValid(String value, Locale locale); > >> > >>The top two methods do four things: > >>1. Pull the necessary parameters out of field variables (ie > >>"datePattern" out of a field var to be passed to the third method) > >>2. Extract the field value as a String > >>3. Return true if the value is blank or null since the field may not be > >>required (the bottom two methods return false in such a case) > >>4. Delegate handling to the bottom two methods > >> > >> > > > >Are these steps going to be duplicated for every pluggable validator? If > >so, maybe we could front DateValidator and friends with something like > >FieldChecks that contains the glue code? > > > >David > > > > > > > >>Any objections? > >> > >>Don > >> > >> > >>David Graham wrote: > >> > >> > >> > >>>I'd be interested in any patches in this area so please open a bugzilla > >>>ticket for this. It sounds like you have some good ideas for making > >>>validator easier to use; I just don't have much time right now to look > >>>into it more. > >>> > >>>Thanks, > >>>David > >>> > >>>--- Don Brown wrote: > >>> > >>> > >>> > >>> > >>>>After looking through the different validator usages - Struts, Spring, > >>>> > >>>> > >>>>and the unit tests - I'm a bit confused why commons-validator doesn't > >>>>ship with functional validators that can be used directly and not > >>>> > >>>> > >>hidden > >> > >> > >>>>by some adapter. commons-validator contains validator classes, yes, > >>>> > >>>> > >>but > >> > >> > >>>>you still need to create a validator adapter class that accepts at > >>>> > >>>> > >>least > >> > >> > >>>>the bean and the Field object to interact with the validator. > >>>>Furthermore, this adapter class (Struts and Spring both call it > >>>>CheckFields) contains framework specific references, usually dealing > >>>>with their errors system. > >>>> > >>>>The problem with this approach is it requires huge levels of > >>>> > >>>> > >>duplication > >> > >> > >>>>as each container needs to write their own adapter and error creation > >>>>code. I'm particularly confused because it seems the solution already > >>>> > >>>> > >>>>exists within commons-validator - ValidationResult(s). I would think > >>>> > >>>> > >>a > >> > >> > >>>>better approach would be for commons-validator to provide adapters for > >>>> > >>>> > >>>>every validator to extract the field information from Field and pass > >>>> > >>>> > >>it > >> > >> > >>>>along to the actual validator. The process of creating messages > >>>> > >>>> > >>should > >> > >> > >>>>be left to the class that called validator.validate() to process > >>>>ValidationResults and handle the errors in a container-specific way. > >>>>This way, new containers that want to use commons-validator don't have > >>>> > >>>> > >>>>to write their own monolithic adapter class but can use validators as > >>>>they are. If commons-validator wants to separate a validator into a > >>>>commons-validator adapter class and a actual validation class, that > >>>> > >>>> > >>is > >> > >> > >>>>fine, but there really isn't any need for that adapter to depend on a > >>>>container. > >>>> > >>>>If my premise is sound and the solution agreeable, I would be willing > >>>> > >>>> > >>to > >> > >> > >>>>do the leg work of writing container-independent adapters for each of > >>>>the validators. > >>>> > >>>>Don > >>>> > >>>>--------------------------------------------------------------------- > >>>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > >>>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org > >>>> > >>>> > >>>> > >>>> > >>>> > >>> > >>> > >>> > >>>__________________________________ > >>>Do you Yahoo!? > >>>Yahoo! Domains � Claim yours for only $14.70/year > >>>http://smallbusiness.promotions.yahoo.com/offer > >>> > >>>--------------------------------------------------------------------- > >>>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > >>>For additional commands, e-mail: commons-dev-help@jakarta.apache.org > >>> > >>> > >>> > >>> > >>> > >>--------------------------------------------------------------------- > >>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > >>For additional commands, e-mail: commons-dev-help@jakarta.apache.org > >> > >> > >> > > > > > > > > > > > >__________________________________ > >Do you Yahoo!? > >Friends. Fun. Try the all-new Yahoo! Messenger. > >http://messenger.yahoo.com/ > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > >For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org