spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.37k stars 38.04k forks source link

PropertyTypeConverter / BeanWrapper ignores any PropertyEditors created by custom BeanInfo implementations. [SPR-1723] #6420

Closed spring-projects-issues closed 12 years ago

spring-projects-issues commented 18 years ago

Chris Wood opened SPR-1723 and commented

The beans.PropertyTypeConverter class ignores any custom PropertyEditors registered within the PropertyDescriptors created by a custom BeanInfo.

The problem is in the doTypeConversionIfNecessary method, this should call the getPropertyDescriptor method in the BeanInfo class to get the property descriptor, and for JDK 1.5 + call createPropertyEditor to create the editor, or otherwise call getPropertyEditorClass and instantiate the class.

This change would require that the PropertyTypeConverter take a BeanWrapper as it's constructor argument, rather than a PropertyEditorRegistrySupport since it needs to get access to the bean being edited.

My feeling is that any custom editors registered in the registry should be used first, followed by resolving the editor from the BeanInfo class, and finally fall back to the defaults.

I'll provide a patch shortly.


Affects: 2.0 M2

Attachments:

Issue Links:

1 votes, 0 watchers

spring-projects-issues commented 18 years ago

Chris Wood commented

Actualy I'm not entirely convinced of this order of operations, I think any registered custom property editors registered for a particular property should be used first, followed by the BeanInfo, then followed by the custom property editor by type, and finally the default one.

This is going to be much harder to code however, so I'll go with what I've suggested above.

spring-projects-issues commented 18 years ago

Chris Wood commented

The changed file, a patch vs 2.0-m2, and a test case that reproduces the issue.

Note that the test case only works under a Java5 JDK as it relies on an API change made in 1.5, however the patch will work in older JDKs.

spring-projects-issues commented 18 years ago

Chris Wood commented

One other thing: You might want to document the use of BeanInfo types, or at least point to the relivent core java documentation.

spring-projects-issues commented 18 years ago

Juergen Hoeller commented

Thanks for the suggestion! I've implemented this based on your refined order: first property-specific editors, then BeanInfo, then type-specific editors, then default editors.

For JDK <1.5, I sticked with classic PropertyEditor class instantiation. The support for constructors with an Object argument seems to have been introduced in JDK 1.5, so we only support it there as well - else we'll always use the default constructor for an exposed property editor class.

Juergen

spring-projects-issues commented 18 years ago

Chris Wood commented

Ok sounds reasonable with the 1.5 thing. (I'm not bothered either way since I'm using 1.5, as long as the 1.5 behaviour gets followed).

Note that this issue makes #6205 unnecicary, it could probably get rejected since with this patch the functionality is available anyhow in a more standard way.

spring-projects-issues commented 18 years ago

Rick Evans commented

Added some documentation describing BeanInfo style usage to the 'PropertyEditors, data binding, validation and the BeanWrapper' chapter of the Spring reference documentation (currently Chapter 5).