Would there be any objections to me removing the validators from the fieldtype*.xml files?
-Adrian --- On Sat, 6/26/10, David E Jones <d...@me.com> wrote: > From: David E Jones <d...@me.com> > Subject: Re: Discussion: Entity Engine Field Validators > To: dev@ofbiz.apache.org > Date: Saturday, June 26, 2010, 9:58 AM > > The validators are only used in the WebTools Entity Data > Maintenance screens. > > They are intentionally not used in other parts of the > project as validation is best in the logic layer, and not in > the data layer (makes things far more reusable and > flexible). > > I actually consider these to be a bad design from very > early on in the project when the entity engine was one of > the only tools in the framework, and IMO it would be better > to remove them than to support them everywhere. > > -David > > > On Jun 26, 2010, at 10:54 AM, Adrian Crum wrote: > > > The entity engine allows you to specify field > validators in two places: in the fieldtypeXxx.xml files and > in the the entity definition. > > > > The validators in the fieldtype files are not used as > far as I can tell. > > > > The validators in the entity definitions require > complicated client code to use them - they are not used > automatically by the entity engine. > > > > The bottom line is, specifying a validator in either > location does absolutely nothing. I don't know if this was > designed this way or not. > > > > I have a design in mind that I think will be > better... > > > > 1. Create a validator interface that can be used > throughout the project: > > > > public interface Validator { > > void isValid(Object obj; > > } > > > > The isValid method throws an IllegalArgumentException > if the object is not valid. > > > > 2. Set up a library of commonly used validators and > put them in a Validator factory. Modify ModelField and > ModelFieldType so they load validators from the factory. > > > > 3. Have ModelField and ModelFieldType implement > Validator. Those classes delegate the isValid method call to > their contained validators. > > > > 4. Modify GenericEntity.set method to call the > ModelField's isValid method. > > > > The advantages to this approach are: > > > > 1. Validators are reusable. The same validators could > be used on service parameters for example. > > 2. Client code is shielded from validation details. > Just call the isValid method. > > 3. OFBiz users can implement custom Validator > implementations and add them to the Validator factory. > > > > What do you think? > > > > -Adrian > > > > > > > > > >