Announcement Announcement Module
Collapse
No announcement yet.
How does declarative custom editor setup work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How does declarative custom editor setup work

    Hello,

    I'm trying to register a custom editor in a declarative way.

    Code:
        <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
            <property name="customEditors">
                <map>
                    <entry key="mypackage.myType">
                        <bean class="mypacke.myEditor"/>
                    </entry>
                </map>
            </property>
        </bean>
    The Editor is initialized but isn't used for wrapping my type. If i register the same editor in the initBinder() method of my controller, everything works fine.

    What's my mistake?


    Best,
    Oliver

  • #2
    I guess you are using a BeanFactory subtype. Try using an ApplicationContext subtype instead (e.g. ClassPathXmlApplicationContext).

    Only ApplicationContexts do automatic registering of property editors. For plain BeanFactories you have to trigger registration explicitly.

    Regards,
    Andreas

    Comment


    • #3
      Originally posted by Andreas Senft
      I guess you are using a BeanFactory subtype. Try using an ApplicationContext subtype instead (e.g. ClassPathXmlApplicationContext).

      Only ApplicationContexts do automatic registering of property editors. For plain BeanFactories you have to trigger registration explicitly.
      Uhmm. I don't understand. :oops:

      I put that bean definition in applicationContext.xml and I did a log.debug() in my Editor's constructor - that debug line is printed when spring boots up.

      Comment


      • #4
        Originally posted by ojs
        I put that bean definition in applicationContext.xml and I did a log.debug() in my Editor's constructor - that debug line is printed when spring boots up.
        The creation of your editor does not seem to be the problem. However it still needs to be registered in order to being invoked properly.

        Maybe you can just post the code that loads in your applicationContext.xml.

        Regards,
        Andreas

        Comment


        • #5
          Originally posted by Andreas Senft
          Maybe you can just post the code that loads in your applicationContext.xml.
          I already pasted the code (see above). Thats all. I already had the feeling that this isn't enough, but I don't know what I need more.

          Comment


          • #6
            That was not what I meant. I wanted to see the code where you *instantiate* your BeanFactory/ApplicationContext. That's where you specify that applicationContext.xml is to be processed.

            Something like this:
            Code:
            ApplicationContext ctx = new ClassPathXmlApplicationContext&#40;"applicationContext.xml"&#41;;
            
            ctx.getBean&#40;...&#41;;
            Regards,
            Andreas

            Comment


            • #7
              Originally posted by Andreas Senft
              That was not what I meant. I wanted to see the code where you *instantiate* your BeanFactory/ApplicationContext.
              Ahh. I see. Well, it's a web application, so my web.xml looks like this:

              Code:
                  <context-param>
                      <param-name>contextConfigLocation</param-name>
                      <param-value>
                          /WEB-INF/conf/global-service.xml
                      </param-value>
                  </context-param>
              
                  <!-- ... -->
              
                  <listener>
                      <listener-class>
                          org.springframework.web.context.ContextLoaderListener
                      </listener-class>
                  </listener>
              
                  <!-- ... -->
              
                  <servlet>
                      <servlet-name>myapp</servlet-name>
                      <servlet-class>
                          org.springframework.web.servlet.DispatcherServlet
                      </servlet-class>
                      <load-on-startup>1</load-on-startup>
                  </servlet>

              Oliver

              Comment


              • #8
                Ok. So it is an ApplicationContext and should normally work as you have configured it.

                Then I think it's about registration. For which type do you register the editor? You have to register it for the type of the property, not for the type of the class containing it. Maybe that is the problem.

                Regards,
                Andreas

                Comment


                • #9
                  Originally posted by Andreas Senft
                  Then I think it's about registration. For which type do you register the editor? You have to register it for the type of the property, not for the type of the class containing it. Maybe that is the problem.
                  I register the editor for the type, not for the class containting that type. That cannot be the problem.


                  Oliver

                  Comment


                  • #10
                    I fear, I'm running out of ideas

                    One last thing I recall is, that a recent Spring version (1.2.2) had some issues with BeanPostProcessors. I haven't been following this issue very closely, but think it should be fixed in 1.2.3. It was about beans not being eligible for post processors. If that would be the case here, you could probably find clues in the logfile (debug level).
                    Maybe an upgrade does help.

                    Regards,
                    Andreas

                    Comment


                    • #11
                      Originally posted by Andreas Senft
                      One last thing I recall is, that a recent Spring version (1.2.2) had some issues with BeanPostProcessors. I haven't been following this issue very closely, but think it should be fixed in 1.2.3. It was about beans not being eligible for post processors. If that would be the case here, you could probably find clues in the logfile (debug level).
                      Maybe an upgrade does help.
                      I already tried my luck and updated to 1.2.3 already. No luck. I posted a jira issue: http://opensource.atlassian.com/proj...rowse/SPR-1210

                      Thanks for your help!

                      Comment

                      Working...
                      X