|
From: Keith D. <kd...@cs...> - 2004-03-17 04:37:33
|
Anna, I took a look and verified what you're seeing is definitely a bug. Good catch. I'll let you know as soon as I get it resolved and will incorpora= te a test to verify it's fixed. Thanks! Keith ----- Original Message -----=20 From: "Keith Donald" <kd...@cs...> To: <spr...@li...> Sent: Tuesday, March 16, 2004 7:02 PM Subject: RE: [Springframework-developer] declarative rules-based bean validator w/ attributes in sandbox > Anna, > > Did you recompile the attributes after you changed the property name? = I > know I quite often forget that step. There is a build.xml file in the test > area with a target that will do this for you. I *hope* that's what it was, > but I will take a look later. > > Thanks, > Keith > > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On Behal= f Of > Anna Chen > Sent: Tuesday, March 16, 2004 5:44 PM > To: spr...@li... > Subject: RE: [Springframework-developer] declarative rules-based bean > validator w/ attributes in sandbox > > > Keith, > > > Thanks a lot! > > However, I have found another bug... > The attribute name has to be the same as the class name > > After I change name to theName in Pet class, I got > > Testsuite: org.springframework.validation.BeanValidatorTestSuite > Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.461 sec > > Testcase: testErrorsValidationWorkflow took 0.421 sec > Caused an ERROR > No property 'name' in class [org.springframework.validation.Pet] > org.springframework.beans.FatalBeanException: No property 'name' in cla= ss > [org.springframework.validation.Pet] > at > org.springframework.beans.CachedIntrospectionResults.getPropertyDescripto= r(C > achedIntrospectionResults.java:114) > at > org.springframework.beans.BeanWrapperImpl.getPropertyDescriptor(BeanWrapp= erI > mpl.java:776) > at > org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImp= l.j > ava:453) > at > org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrappe= rIm > pl.java:386) > at > org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(B= ean > WrapperImpl.java:308) > at > org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImp= l.j > ava:440) > at > org.springframework.validation.BindException.rejectValue(BindException.ja= va: > 107) > at > org.springframework.validation.rules.AbstractPropertyValidationRule.invok= eRe > jectValue(AbstractPropertyValidationRule.java:63) > at > org.springframework.validation.support.ValidationResultsErrorsCollector.v= ali > dationErrorOccured(ValidationResultsErrorsCollector.java:44) > at > org.springframework.validation.support.PropertyValidatorImpl.validateProp= ert > yValue(PropertyValidatorImpl.java:98) > at > org.springframework.validation.support.PropertyValidatorImpl.validateCurr= ent > PropertyValue(PropertyValidatorImpl.java:83) > at > org.springframework.validation.support.BeanInfoBeanValidator.processBeanI= nfo > Validators(BeanInfoBeanValidator.java:113) > at > org.springframework.validation.support.BeanInfoBeanValidator.processBeanI= nfo > Validators(BeanInfoBeanValidator.java:117) > at > org.springframework.validation.support.BeanInfoBeanValidator.validateBean= (Be > anInfoBeanValidator.java:51) > at > org.springframework.validation.support.DefaultBeanValidationService.valid= ate > (DefaultBeanValidationService.java:53) > at > org.springframework.validation.support.DefaultBeanValidationService.valid= ate > (DefaultBeanValidationService.java:48) > at > org.springframework.validation.BeanValidatorTestSuite.testErrorsValidatio= nWo > rkflow(BeanValidatorTestSuite.java:76) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java= :39 > ) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI= mpl > .java:25) > at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:232) > at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279) > at > org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135) > at > org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:233) > at org.apache.commons.jelly.tags.core.IfTag.doTag(IfTag.java:88) > at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279) > at > org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135) > at > org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:233) > at com.werken.werkz.jelly.GoalTag$1.performAction(GoalTag.java:128) > at com.werken.werkz.Goal.fire(Goal.java:639) > at com.werken.werkz.Goal.attain(Goal.java:575) > at com.werken.werkz.Goal.attainPrecursors(Goal.java:488) > at com.werken.werkz.Goal.attain(Goal.java:573) > at > org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:44= 8) > at org.apache.maven.MavenSession.attainGoals(MavenSession.java:348) > at org.apache.maven.cli.App.doMain(App.java:543) > at org.apache.maven.cli.App.main(App.java:1109) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java= :39 > ) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI= mpl > .java:25) > at com.werken.forehead.Forehead.run(Forehead.java:551) > at com.werken.forehead.Forehead.main(Forehead.java:581) > > > Thanks, > > Anna > > > > > > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...]On Behalf= Of > Keith Donald > Sent: Tuesday, March 16, 2004 2:58 PM > To: spr...@li... > Subject: Re: [Springframework-developer] declarative rules-based bean > validator w/ attributes in sandbox > > > Anna, > > There is a indirect relationship between the two. > > The BeanValidatorBuilder instantiates PropertyValidators for a bean's > properties and places them in that beans corresponding BeanInfo. The > DefaultBeanValidationService then looks up those validators by querying the > BeanInfo and subsequently processes them. So there is a level of > indirection there. > > We're basically leveraging the existing javabeans metadata classes as > opposed to rolling our own cache (which simplifies things and seems qui= te > elegant.) > > More specifically, a validated bean will have the following characteristics: > > 1. The BeanInfo.beanDescriptor has the property > BeanValidatorConstants.VALIDATED set to "true". > > 2. For each validated property, it's propertyDescriptor also has the > property BeanValidatorConstants.VALIDATED also set to "true". In addition, > the BeanValidatorConstants.VALIDATOR property stores a reference to the > corresponding PropertyValidator, which encapsulates all the > PropertyValidationRules. > > What the defaultBeanValidationService does is query the BeanInfo of the bean > class when it is asked to validate a bean. If the BeanDescriptor is no= t > marked as "validateable", the service returns, doing nothing. Else it runs > over each property doing the same thing recursively down the object gra= ph, > invoking validate() on any found PropertyValidators. > > One issue that likely needs to be addressed is a result of BeanInfo caching > differences between JDK 1.3 and 1.4. I know under JDK 1.4 BeanInfo > instances are shared by the Introspector (caching is built in.) I believe > under JDK 1.3, however, that is not the case--new BeanInfo copies are > returned on each call to the Introspector. :-( > > Keith > > ----- Original Message ----- > From: "Anna Chen" <ac...@er...> > To: <spr...@li...> > Sent: Tuesday, March 16, 2004 3:09 PM > Subject: RE: [Springframework-developer] declarative rules-based bean > validator w/ attributes in sandbox > > > > 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 exist= s > > 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=3D"beanValidationService" > > > class=3D"org.springframework.validation.support.DefaultBeanValidationServ= ice"> > > <property name=3D"beanValidatorSource"><ref > > bean=3D"attributesValidatorSource"/></property> > > </bean> > > > > <bean id=3D"attributesValidatorSource" > > class=3D"org.springframework.validation.support.AttributesValidatorSo= urc > > e"/> > > > > <bean id=3D"beanValidatorBuilder" > > class=3D"org.springframework.validation.support.BeanValidatorBuilder"= > > > <constructor-arg index=3D"0"> > > <description>The validated bean type</description> > > <value>org.springframework.validation.Pet</value> > > </constructor-arg> > > <property name=3D"propertyValidators"> > > <map> > > <entry key=3D"name.lastName"> > > <bean class=3D"org.springframework.validation.rules.Require= d"/> > > </entry> > > <entry key=3D"favoriteToy"> > > <set> > > <bean class=3D"org.springframework.validation.rules.Required"/> > > <bean class=3D"org.springframework.validation.rules.MaxLength"> > > <constructor-arg > index=3D"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 bea= n > > 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 agre= e > > > 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 ther= e > > > > > 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 > > > =3D > > > > > > plain > > > > > > java. This is in addition to support for defining validation > rules > > on > > > =3D > > > > > > beans > > > > > > via source markup. > > > > > > > > > > > > Here's an example on how to use it: > > > > > > > > > > > > Spring IoC configuration > > > > > > > > > > > > <bean id=3D3D"validatorBuilder" > > > > > > > class=3D3D"org.springframework.validation.support.ValidatorBuilder"/> > > > > > > <constructor-arg index=3D3D"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=3D3D"name.lastName"> > > > > > > <value><bean > > > > > > class=3D3D"org.springframework.validation.rules.Required"/></= val > > > > > > ue> > > > > > > </entry> > > > > > > <entry key=3D3D"favoriteToy"> > > > > > > <value> > > > > > > <set> > > > > > > <bean > > > > > > class=3D3D"org.springframework.validation.rules.Required"/> > > > > > > <bean > > > > > > class=3D3D"org.springframework.validation.rules.MaxLength"> > > > > > > =3D09 > > > > > > <constructor-arg>25</constructor-arg> > > > > > > > > > > > > </bean> > > > > > > </set> > > > > > > </value> > > > > > > </entry> > > > > > > </map> > > > > > > </bean> > > > > > > > > > > > > Java > > > > > > > > > > > > BeanValidatorBuilder builder =3D3D new =3D > > > > > > BeanValidatorBuilder(Pet.class); > > > > > > > > > > > > builder.setPropertyValidator("name.lastName", new > > Required()); > > > > > > > > > > > > > > > Set toyRules =3D3D 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=3D1470&alloc_id=3D3638&op=3Dc= lick > > > > > _______________________________________________ > > > > > 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=3D1470&alloc_id=3D3638&= op=3Dcl > > > > ick > > > > _______________________________________________ > > > > 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=3D1470&alloc_id=3D3638&= op=3Dcl > > > > ick > > > > _______________________________________________ > > > > 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 syste= m > > > administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op= =3Dclic > > > k > > > _______________________________________________ > > > Springframework-developer mailing list > > > Spr...@li... > > > https://lists.sourceforge.net/lists/listinfo/springframework-develo= per > > > > > > > > ------------------------------------------------------- > > 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=3D1470&alloc_id=3D3638&op=3D= click > > _______________________________________________ > > Springframework-developer mailing list > > Spr...@li... > > https://lists.sourceforge.net/lists/listinfo/springframework-develope= r > > > > > > > > > > > > > > > > ------------------------------------------------------- > > 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=3D1470&alloc_id=3D3638&op=3D= click > > _______________________________________________ > > Springframework-developer mailing list > > Spr...@li... > > https://lists.sourceforge.net/lists/listinfo/springframework-develope= r > > > > ------------------------------------------------------- > 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=3D1470&alloc_id=3D3638&op=3Dc= lick > _______________________________________________ > 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=3D1470&alloc_id=3D3638&op=3Dc= lick > _______________________________________________ > 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_id638&op=CCk > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |