|
From: Anna C. <ac...@er...> - 2004-03-16 20:09:26
|
Keith,
Could you tell me the relationship between DefaultBeanValidationService and
beanValidatorBuilder?
I could not find where beanValidatorBuilder get called.
Thanks,
Anna
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of Keith Donald
Sent: Saturday, March 13, 2004 6:44 PM
To: spr...@li...
Subject: Re: [Springframework-developer] declarative rules-based bean
validator w/ attributes in sandbox
Anna,
I've since been updating the unit tests of the declarative validation stuff,
so I thought I'd go ahead and attach a working sample that also exists in
the sandbox/test/org/springframework/validation test area. As we do more
testing, we'll get better samples, too.
The sample below shows 3 bean declarations: the beanValidatorService is the
main validator interface to the subsystem, and here is using the
attributesValidatorSource to load on-demand validator information for beans
using commons-attributes. The beanValidatorBuilder is an example of how to
configure validation rules for bean properties declaratively using Spring.
In this example, the builder is configuring rules for the "name.lastName"
and "favoriteToy" properties of the Pet bean (specifically the key in the
propertyValidators map is the propertyName, and the value is a set of
PropertyValidationRule instances.)
--------------
<bean id="beanValidationService"
class="org.springframework.validation.support.DefaultBeanValidationService">
<property name="beanValidatorSource"><ref
bean="attributesValidatorSource"/></property>
</bean>
<bean id="attributesValidatorSource"
class="org.springframework.validation.support.AttributesValidatorSource"/>
<bean id="beanValidatorBuilder"
class="org.springframework.validation.support.BeanValidatorBuilder">
<constructor-arg index="0">
<description>The validated bean type</description>
<value>org.springframework.validation.Pet</value>
</constructor-arg>
<property name="propertyValidators">
<map>
<entry key="name.lastName">
<bean class="org.springframework.validation.rules.Required"/>
</entry>
<entry key="favoriteToy">
<set>
<bean class="org.springframework.validation.rules.Required"/>
<bean class="org.springframework.validation.rules.MaxLength">
<constructor-arg index="0"><value>25</value></constructor-arg>
</bean>
</set>
</entry>
</map>
</property>
</bean>
Keith
----- Original Message -----
From: "Keith Donald" <kd...@cs...>
To: <spr...@li...>
Sent: Thursday, March 11, 2004 12:19 AM
Subject: Re: [Springframework-developer] declarative rules-based bean
validator w/ attributes in sandbox
> Anna,
>
> Thanks... yea, I typed that by hand in the email from memory and I see I
> made at least one mistake with a closing tag in the first bean
declaration.
> :-) I'll be sure to correct anything like that when we get some
samples/docs
> out.
>
> BTW, guys thanks for those commons attributes tips. I haven't had time to
> go through their docs in detail and I really appreciate it. I agree we
> should keep the validation rule hierarchy as is.
>
> Keith
>
> ----- Original Message -----
> From: "Anna Chen" <ac...@er...>
> To: <spr...@li...>
> Sent: Wednesday, March 10, 2004 4:04 PM
> Subject: RE: [Springframework-developer] declarative rules-based bean
> validator w/ attributes in sandbox
>
>
> > Keith
> >
> > I don't think that the Spring IoC configuration is a valid one according
> to
> > http://www.springframework.org/dtd/spring-beans.dtd
> >
> >
> > Anna
> >
> > -----Original Message-----
> > From: spr...@li...
> > [mailto:spr...@li...]On Behalf
> > Of Keith Donald
> > Sent: Wednesday, March 10, 2004 8:10 AM
> > To: spr...@li...
> > Subject: Re: [Springframework-developer] declarative rules-based bean
> > validator w/ attributes in sandbox
> >
> >
> > Correct me if I'm wrong, but I don't think there is. However, I know if
> > you're using Eclipse, the sandbox code (including tests) automatically
> gets
> > incrementally compiled in target/other-classes, which is automatically
put
> > in the classpath. So I have been basically running everything in the
> > sandbox from Eclipse directly.
> >
> > Keith
> >
> > ----- Original Message -----
> > From: <sam...@ma...>
> > To: <spr...@li...>
> > Sent: Wednesday, March 10, 2004 6:42 AM
> > Subject: RE: [Springframework-developer] declarative rules-based bean
> > validator w/ attributes in sandbox
> >
> >
> > > 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/
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.Net email is sponsored by: IBM Linux Tutorials
> > > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > > GenToo technologies. Learn everything from fundamentals to system
> > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux Tutorials
> > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > GenToo technologies. Learn everything from fundamentals to system
> > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux Tutorials
> > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > GenToo technologies. Learn everything from fundamentals to system
> > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|