PDA

View Full Version : Validation


PVG
02-26-2007, 02:29 PM
Hi,

I want to use the Validator framework for validating my business objects.

I have the following situation. A class myClassA has a collection of myClassB objects. Is it possible, using the out of the box validator and validator groups, to define a validator that validates all of the entries in the myClassB collection on the object of classA.

I know there is the possibility to have validator references, but I have the impression that this is only usefull for one-to-one object relationships and not one-to-many relations like I have.

How would I best do this? Writing a custom Validator is off course always possible. This validator would then take a navigationexpression to get to the collection of objects and would refer to a validator group. This validator group contains then the validators that must be executed.

Any information or feedback is always welcome.

KR

Patrick

PVG
02-26-2007, 05:18 PM
Hi,

A possible way to implement the above requirement would be to subclass the ValidatorReference class by a CustomValidatorReference class.

This CustomValidatorReference class would then be configured in the XMLfile as follows
<v:ref context="CollectionOfObjectsB" name="ValidatorName" type="A.B.C.CollectionValidatorReference"/>

However the Validation XSD does not allow for the type attirbute on a v:ref element.

Also the ValidationConfigParser must then be extended in the ParseValidatorReference method to look for the type attribute, if not present take as default as it is currently.

This way would seem to me the most logical implementation of this functionality. The ValidatorReference allready contains the logic of retrieving the property.

One other thing that is needed on this collection validator, is the notion of whether all objects in the collection must be valid or if it suffices if one object in the collection is valid in order for the validation to succeed.

ANy feedback please.

KR

Patrick

Aleks Seovic
02-28-2007, 08:40 PM
This functionality has already been implemented.

See this topic for the original request and implementation details.

- Aleks