Return-Path: Delivered-To: apmail-cayenne-dev-archive@www.apache.org Received: (qmail 50481 invoked from network); 10 Mar 2010 13:33:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Mar 2010 13:33:49 -0000 Received: (qmail 12689 invoked by uid 500); 10 Mar 2010 13:33:19 -0000 Delivered-To: apmail-cayenne-dev-archive@cayenne.apache.org Received: (qmail 12661 invoked by uid 500); 10 Mar 2010 13:33:19 -0000 Mailing-List: contact dev-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list dev@cayenne.apache.org Received: (qmail 12479 invoked by uid 99); 10 Mar 2010 13:33:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Mar 2010 13:33:19 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.218.220] (HELO mail-bw0-f220.google.com) (209.85.218.220) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Mar 2010 13:33:12 +0000 Received: by bwz20 with SMTP id 20so4108303bwz.12 for ; Wed, 10 Mar 2010 05:32:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.34.131 with SMTP id l3mr860549bkd.36.1268227971501; Wed, 10 Mar 2010 05:32:51 -0800 (PST) In-Reply-To: References: From: Michael Gentry Date: Wed, 10 Mar 2010 08:32:31 -0500 Message-ID: <5adb61291003100532v30b86378m785f891516101f21@mail.gmail.com> Subject: Re: Automated Validation of Attributes To: dev@cayenne.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Part of this would depend on your UI, too. If you are using Tapestry 5, for example, it has similar validation built in. Say you have a text field with an id=3DfirstName, T5 will invoke (if present) onValidateFromFirstName(String newFirstName) for you before ever calling the setter. If you throw an exception out of that, T5 will know not to call the setter. Once you've gone past that logic (which would be the case you mention) it is a bit too late ... Not sure if that made sense (I'm still waking up), but I hope so. :-) mrg On Tue, Mar 9, 2010 at 10:42 PM, Andrew Lindesay wrote= : > Hello; > > As you may know, WebObjects/EOF has the protocol; > > =A0 =A0 =A0 =A0NSValidation > > Specifically, this protocol implements the following two methods; > > =A0 =A0 =A0 =A0Object validateTakeValueForKeyPath(Object value, String ke= yPath) > =A0 =A0 =A0 =A0Object validateValueForKey(Object value, String key) > > The effect is that when a client tries to write a property "foo", it will= ultimately try to invoke; > > =A0 =A0 =A0 =A0Object validateFoo(Object value) throws NSValidation.Valid= ationException > > ...before... > > =A0 =A0 =A0 =A0setFoo(Object value) > > ...in order to either "repair" the value before assigning or to throw an = exception. =A0This is very handy from the user-interface perspective. =A0Fo= r each attribute of an entity, this technique is also automatically used in= the case of "validateForSave()" which means that aside from inter-attribut= e validation, per-attribute validations can be implemented just once. > > To provide this same behaviour to Cayenne, I would like to put forward th= e idea to implement something similar; > > =A0 =A0 =A0 =A0validatedWriteProperty(ValidationResult vr, String propNam= e, Object value) > =A0 =A0 =A0 =A0validatedWriteNestedProperty(ValidationResult vr, String p= ropName, Object value) > > This would use (cached) reflection to look for a "validate" method and fi= re that before writing the property. =A0For each attribute of a DataObject'= s entity, these methods would be fired from; > > =A0 =A0 =A0 =A0void validateForSave(ValidationResult validationResult) > > Does this make sense in the context of Cayenne? > > Regards; > > ___ > Andrew Lindesay > www.lindesay.co.nz > >