Hi all.
I am really new to spring so I would like some feedback regarding my implementation of custom PropertyEditorRegistrars.
I realize that DI is the way to go and I really had to think a long while to set the following up.
The problem was that I couldnt use org.springframework.beans.factory.config.CustomEdi torConfigurer since they are not available to form controllers AFAIK.
After searching around I didnt find a implementation that implements PropertyEditorRegistrar so I came up with the following two classes:
Code:public abstract class CustomPropertyEditorSupport extends PropertyEditorSupport { public abstract PropertyEditorSupport getPropertyEditor(); }Now I was able to use the following in my servlet.xmlCode:public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar { public void registerCustomEditors(PropertyEditorRegistry registry) { Iterator<Class> it=customPropertyEditorSupport.keySet().iterator(); while(it.hasNext()) { Class clazz=it.next(); PropertyEditorSupport editor=customPropertyEditorSupport.get(clazz).getPropertyEditor(); registry.registerCustomEditor(clazz,editor); } } public void setCustomPropertyEditorSupport(Map<Class,CustomPropertyEditorSupport> customPropertyEditorSupport ) { this.customPropertyEditorSupport=customPropertyEditorSupport; } Map<Class,CustomPropertyEditorSupport> customPropertyEditorSupport; }
and then be able to use the bean myEditorClass with org.springframework.beans.factory.config.CustomEdi torConfigurer aswell.Code:<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="propertyEditorRegistrars"> <list> <ref bean="customPropertyEditorRegistrar"/> </list> </property> </bean> <bean id="customPropertyEditorRegistrar" class="se.xxx.invoice.CustomPropertyEditorRegistrar"> <property name="customPropertyEditorSupport"> <map> <entry key="se.xxx.invoice.classes.myClass"> <bean class="se.xxx.invoice.CustomPropertyEditorSupport"> <lookup-method name="getPropertyEditor" bean="myEditorClass"/> </bean> </entry> </map> </property> </bean>
Is this the right way to go? Is there already any standard way of doing this?
Best regards,
Jonas


Reply With Quote