I want to create a custom PropertyEditor and found the following in Spring documentation
Spring uses the java.beans.PropertyEditorManager to set the search path for property editors that might be needed. The search path also includes sun.bean.editors, which includes PropertyEditor implementations for types such as Font, Color, and most of the primitive types. Note also that the standard JavaBeans infrastructure will automatically discover PropertyEditor classes (without you having to register them explicitly) if they are in the same package as the class they handle, and have the same name as that class, with 'Editor' appended;
I have a class which holds several enums as inner elements
I have 2 enumerated types Enumerated types Country & Curency the class names are
com.anoop.spring.AllEnums$Country
and
com.anoop.spring.AllEnums$Currency
And correspondingly I have two Property Editors CountryEditor and CurrencyEditor
com.anoop.spring.AllEnums$CountryEditor
and
com.anoop.spring.AllEnums$CurrencyEditor
Now I have a wrapper bean as given below
Now I have a MultiActionController with a method as given below
The problem is Spring is never using my PropertyEditors for setting the properties country and currency of the bean com.anoop.spring.Cash because of which I get exception with the following query string country=IN¤cy=INR at the same time country=INDIA¤cy=RUPEE works fine
Could you please tell me what went wrong with my PropertyEditor definitions.
I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
I think this is not needed because The Editor is in the default search path of PropertyManager
My type class is com.anoop.spring.AllEnumClass$Country and its editor is com.anoop.spring.AllEnumClass$CountryEditor by convention it fits to the default search path where PropertyManager looks for the Property Editors. This is what I found in spring official documentation on PropertyEditors
Spring uses the java.beans.PropertyEditorManager to set the search path for property editors that might be needed. The search path also includes sun.bean.editors, which includes PropertyEditor implementations for types such as Font, Color, and most of the primitive types. Note also that the standard JavaBeans infrastructure will automatically discover PropertyEditor classes (without you having to register them explicitly) if they are in the same package as the class they handle, and have the same name as that class, with 'Editor' appended;
Anoop Krishnan
Ranch Hand
Joined: May 03, 2001
Posts: 163
posted
0
I found the problem . It is the PropertyEditor as a inner class . Property Manager is failing to create a new instance of the property editor when it is an inner class (I do not know why !!!) but when I created a class with the name com.anoop.spring.AllEnums$CountryEditor it worked [ February 04, 2008: Message edited by: Anoop Krishnan ]
I think that you're having a plain old Java problem here. With an inner class, you need to instanciate the class which contains the inner class first. You cannot do the following, and Spring neither :
Spring needs to instanciate AllEnums first, to do something like this :
To avoid this, I can think of at least two ways :
Don't make your enums as inner classes ! Put them in separate files.
Make the inner editors static. If they are statis, Spring will be able to access them.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Problems with Spring's default PropertyEditor search