|
From: Keith D. <kd...@cs...> - 2004-03-17 00:02:21
|
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 Behalf = 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 = class [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:448)= 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 = quite 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 not marked as "validateable", the service returns, doing nothing. Else it = runs over each property doing the same thing recursively down the object = graph, 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=20 > DefaultBeanValidationService and > beanValidatorBuilder? > > I could not find where beanValidatorBuilder get called. > > Thanks, > > Anna > > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...]On=20 > Behalf Of Keith Donald > Sent: Saturday, March 13, 2004 6:44 PM > To: spr...@li... > Subject: Re: [Springframework-developer] declarative rules-based bean=20 > 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=20 > do more testing, we'll get better samples, too. > > The sample below shows 3 bean declarations: the beanValidatorService=20 > is the > main validator interface to the subsystem, and here is using the=20 > attributesValidatorSource to load on-demand validator information for beans > using commons-attributes. The beanValidatorBuilder is an example of=20 > how to > configure validation rules for bean properties declaratively using=20 > Spring. In this example, the builder is configuring rules for the=20 > "name.lastName" and "favoriteToy" properties of the Pet bean=20 > (specifically the key in the propertyValidators map is the=20 > propertyName, and the value is a set of PropertyValidationRule=20 > instances.) > > -------------- > > <bean id=3D"beanValidationService" > class=3D"org.springframework.validation.support.DefaultBeanValidationServ= ice"> > <property name=3D"beanValidatorSource"><ref=20 > bean=3D"attributesValidatorSource"/></property> > </bean> > > <bean id=3D"attributesValidatorSource"=20 > = class=3D"org.springframework.validation.support.AttributesValidatorSourc > e"/> > > <bean id=3D"beanValidatorBuilder"=20 > 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.Required"/> > </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=20 > validator w/ attributes in sandbox > > > > Anna, > > > > Thanks... yea, I typed that by hand in the email from memory and I=20 > > 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=20 > > 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=20 > > 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=20 > > > bean validator w/ attributes in sandbox > > > > > > > > > Correct me if I'm wrong, but I don't think there is. However, I=20 > > > know if > > > you're using Eclipse, the sandbox code (including tests)=20 > > > automatically > > gets > > > incrementally compiled in target/other-classes, which is=20 > > > automatically > put > > > in the classpath. So I have been basically running everything in=20 > > > 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=20 > > > 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=20 > > > > the > src > > > with the > > > > sandbox code and rebuild? > > > > > > > > sam > > > > > > > > Quoting Keith Donald <kd...@cs...>: > > > > > > > > > I checked in a "BeanValidatorBuilder" class in the sandbox=20 > > > > > under validation.support that allows you to declaratively=20 > > > > > assign PropertyValidationRules to bean properties via=20 > > > > > Spring-IoC, through a > > > > > scripting environment such as Groovy/Beanshell, or=20 > > > > > 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>=20 > > > > > <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=20 > > > > > = 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=20 > > > > > 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=20 > > > > Linux tutorial presented by Daniel Robbins, President and CEO of > > > > GenToo technologies. Learn everything from fundamentals to=20 > > > > system > > > > administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= ck > > > > _______________________________________________ > > > > Springframework-developer mailing list=20 > > > > Spr...@li... > > > > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux=20 > > > tutorial presented by Daniel Robbins, President and CEO of GenToo=20 > > > technologies. Learn everything from fundamentals to system=20 > > > = 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=20 > > > tutorial presented by Daniel Robbins, President and CEO of GenToo=20 > > > technologies. Learn everything from fundamentals to system=20 > > > = 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=20 > > of GenToo technologies. Learn everything from fundamentals to system = > > = administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= c > > k > > _______________________________________________ > > 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=20 > GenToo technologies. Learn everything from fundamentals to system=20 > = administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= ck > _______________________________________________ > Springframework-developer mailing list=20 > 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=20 > GenToo technologies. Learn everything from fundamentals to system=20 > = administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= ck > _______________________________________________ > Springframework-developer mailing list=20 > 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=3Dcli= ck _______________________________________________ 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=3Dcli= ck _______________________________________________ Springframework-developer mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-developer |