aspose file tools*
The moose likes Other Application Frameworks and the fly likes Problems with Spring's default PropertyEditor search Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Problems with Spring Watch "Problems with Spring New topic
Author

Problems with Spring's default PropertyEditor search

Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
I am new to Spring.

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
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

How did you register your editors within the CustomEditorConfigurer ?


[My Blog]
All roads lead to JavaRanch
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
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
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 ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.

  •  
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: Problems with Spring's default PropertyEditor search