Announcement Announcement Module
Collapse
No announcement yet.
Registering a custom WebBindingInitializer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Registering a custom WebBindingInitializer

    Hello,

    I am having a problem with registering a custom WebBindingInitializer. I need it because I want @DateTimeFormat on JodaTime DateTime fields in command object to work (shouldn't it work automatically? but it doesn't). So I need to set conversion service. I managed to set it in @InitBinder annotated method in Controller and it works as expected, but I would like to have global setting so I made WebBindingInitializer to do the same logic as @InitBinder:
    Code:
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.core.convert.ConversionService;
    import org.springframework.web.bind.WebDataBinder;
    import org.springframework.web.bind.support.WebBindingInitializer;
    import org.springframework.web.context.request.WebRequest;
    
    public class CommonWebBindingInitializer implements WebBindingInitializer {
    
        @Autowired
        private ConversionService conversionService;
    
        @Override
        public final void initBinder(final WebDataBinder p_binder, final WebRequest p_request) {
            p_binder.setConversionService(conversionService);
        }
    }
    My spring configuration is like in documentation. I read that using <mvc:annotation-driven> can make a problem but I am not using that tag. I tried to debug and found that initBinder method of CommonWebBindingInitializer is not called at all. This is my configuration:

    HTML Code:
    <bean id="conversionService"
          class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>
    
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
       <property name="paramName" value="language" />
    </bean>
    
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
       <property name="alwaysUseFullPath" value="true" />
       <property name="interceptors">
          <list>
                <ref bean="localeChangeInterceptor" />
                <bean class="bla.truc.buc.common.util.web.interceptor.ViewNameResolverInterceptor" />
          </list>
       </property>
       <property name="order" value="1" />
    </bean>
    
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
       <property name="flowRegistry" ref="flowRegistry" />
       <property name="order" value="2" />
    </bean>
    
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    </bean>
    
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
       <property name="flowExecutor" ref="flowExecutor" />
    </bean>
    
    <mvc:default-servlet-handler />
    
    <bean id="fileDownloadView" class="bla.truc.buc.retail.web.view.FileDownloadView" />
    
    <context:component-scan base-package="bla.truc.buc.retail.web.validator, bla.truc.buc.retail.web.property.editor"/>
    
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
       <property name="alwaysUseFullPath" value="true" />
       <property name="interceptors">
          <list>
                <ref bean="localeChangeInterceptor" />
          </list>
       </property>
    </bean>
    
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
       <property name="maxUploadSize" value="5000000" />
    </bean>
    
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
       <property name="cacheSeconds" value="0" />
       <property name="webBindingInitializer">
          <bean class="bla.truc.buc.retail.web.util.CommonWebBindingInitializer" />
       </property>
    </bean
    Thank you!
    Last edited by aurelije; Sep 1st, 2011, 04:51 AM. Reason: typo

  • #2
    I'm actually having the exact same problem, were you able to figure this out? I also tried to debug this and I put in a constructor in the class that implements WebBindingInitializer and found that the constructor is being called, but never the initBinder method which is overwritten.

    Comment


    • #3
      I managed to resolve problem using <mvc:annotation-driven /> meta tag. I could not do it manually.

      So now I don't need bla.truc.buc.retail.web.util.CommonWebBindingIniti alizer class, everything runs OK

      Comment

      Working...
      X