Announcement Announcement Module
Collapse
No announcement yet.
Feedback regarding custom PropertyEditorRegistrar Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Feedback regarding custom PropertyEditorRegistrar

    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();
    }
    Code:
    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;
    }
    Now I was able to use the following in my servlet.xml

    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>
    and then be able to use the bean myEditorClass with org.springframework.beans.factory.config.CustomEdi torConfigurer aswell.

    Is this the right way to go? Is there already any standard way of doing this?

    Best regards,
    Jonas
    Last edited by jontro; May 21st, 2008, 10:23 AM.
Working...
X