|
From: <sam...@ma...> - 2004-03-10 11:59:42
|
Excellent, thanks Keith. On the subject of the sandbox, is there a build
directive to buils the sandbox code, or should I just overwrite the src with the
sandbox code and rebuild?
sam
Quoting Keith Donald <kd...@cs...>:
> I checked in a "BeanValidatorBuilder" class in the sandbox under
> validation.support that allows you to declaratively assign
> PropertyValidationRules to bean properties via Spring-IoC, through a
> scripting environment such as Groovy/Beanshell, or programatically in =
> plain
> java. This is in addition to support for defining validation rules on =
> beans
> via source markup.
>
> Here's an example on how to use it:
>
> Spring IoC configuration
>
> <bean id=3D"validatorBuilder"
> class=3D"org.springframework.validation.support.ValidatorBuilder"/>
> <constructor-arg index=3D"0">
> <description>The validated bean type (class or
> interface) aka 'root entity'</description>
> <value>org.springframework.validation.Pet</value>
> </constructor-arg>
> <map>
> <description>
> A map of property name keys to one or more
> governing property validation rules.
> Nested bean property names from the 'root
> entity' are supported.
> Rule instances may be reused across
> properties if desired.
> </description>
> <entry key=3D"name.lastName">
> <value><bean
> class=3D"org.springframework.validation.rules.Required"/></value>
> </entry>
> <entry key=3D"favoriteToy">
> <value>
> <set>
> <bean
> class=3D"org.springframework.validation.rules.Required"/>
> <bean
> class=3D"org.springframework.validation.rules.MaxLength">
> =09
> <constructor-arg>25</constructor-arg>
>
> </bean>
> </set>
> </value>
> </entry>
> </map>
> </bean>
>
> Java
>
> BeanValidatorBuilder builder =3D new =
> BeanValidatorBuilder(Pet.class);
>
> builder.setPropertyValidator("name.lastName", new Required());
>
> Set toyRules =3D new HashSet();
> toyRules.add(new Required());
> toyRules.add(new MaxLength(255));
> builder.setPropertyValidator("favoriteToy", toyRules);
>
> Keith
sam
http://www.magpiebrain.com/
|