cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <>
Subject Re: Automated Validation of Attributes
Date Wed, 10 Mar 2010 13:32:31 GMT
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=firstName, 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.  :-)


On Tue, Mar 9, 2010 at 10:42 PM, Andrew Lindesay <> wrote:
> Hello;
> As you may know, WebObjects/EOF has the protocol;
>        NSValidation
> Specifically, this protocol implements the following two methods;
>        Object validateTakeValueForKeyPath(Object value, String keyPath)
>        Object validateValueForKey(Object value, String key)
> The effect is that when a client tries to write a property "foo", it will ultimately
try to invoke;
>        Object validateFoo(Object value) throws NSValidation.ValidationException
> ...before...
>        setFoo(Object value)
> order to either "repair" the value before assigning or to throw an exception.  This
is very handy from the user-interface perspective.  For each attribute of an entity, this
technique is also automatically used in the case of "validateForSave()" which means that aside
from inter-attribute validation, per-attribute validations can be implemented just once.
> To provide this same behaviour to Cayenne, I would like to put forward the idea to implement
something similar;
>        validatedWriteProperty(ValidationResult vr, String propName, Object value)
>        validatedWriteNestedProperty(ValidationResult vr, String propName, Object
> This would use (cached) reflection to look for a "validate" method and fire that before
writing the property.  For each attribute of a DataObject's entity, these methods would be
fired from;
>        void validateForSave(ValidationResult validationResult)
> Does this make sense in the context of Cayenne?
> Regards;
> ___
> Andrew Lindesay

View raw message