Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-6817

Portlet MVC - <mvc:annotation-driven /> doesn't inject conversion service and validator in WebDataBinder

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 3.0 GA
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      I have a Spring MVC portlet with one spring configuration file:

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

      <context:component-scan
      base-package="com.cedac.liferay.calcoli.portlets.ammortamenti" />

      <mvc:annotation-driven conversion-service="conversionService" validator="validatorJSR303"/>

      <!-- VIEW RESOLUTION AND RENDERING -->

      <bean id="viewResolver"
      class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
      <property name="basename" value="views"/>
      </bean>

      <!-- Message Bundle -->

      <!-- Message source for this context, loaded from localized "messages_xx" files -->
      <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
      <property name="basenames">
      <list>
      <value>messages</value>
      <value>com.cedac.liferay.calcoli.portlets.ammortamenti.messages</value>
      </list>
      </property>
      </bean>

      </beans>

      and a global spring mvc configuration file:

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

      <!--
      Conversion service
      Supporta anche le annotazioni per la formattazione
      -->
      <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">

      </bean>

      <!-- Validation JSR 303 -->
      <bean id="validatorJSR303" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

      </beans>

      both of them are correctly loaded but when I debug the above method in the controller, conversion service and validator are null.

      @InitBinder
      public void initBinder(WebDataBinder binder) {

      }

      I have to autowire the beans and set them into the binder:

      @Autowired
      private AmmortamentiService ammortamentiService;

      @Autowired
      private Validator validator;

      @InitBinder
      public void initBinder(WebDataBinder binder)

      { //Conversion Service binder.setConversionService(conversionService); //Validator binder.setValidator(ammortamentoValidator); }

        Issue Links

          Activity

          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          I'm afraid that this is a fundamental limitation in Spring 3.0: The MVC namespace works in a Servlet MVC environment only, i.e. within a DispatcherServlet. It has no effect in a Portlet environment. I've added a corresponding warning to the namespace docs.

          We'll revisit this for Spring 3.1. For the time being, in Spring 3.0, you'll have to configure an AnnotationMethodHandlerAdapter bean, passing a ConfigurableWebBindingInitializer into its "webBindingInitializer" property. That nested ConfigurableWebBindingInitializer bean in turn features "conversionService" and "validator" properties.

          Juergen

          Show
          juergen.hoeller Juergen Hoeller added a comment - I'm afraid that this is a fundamental limitation in Spring 3.0: The MVC namespace works in a Servlet MVC environment only, i.e. within a DispatcherServlet. It has no effect in a Portlet environment. I've added a corresponding warning to the namespace docs. We'll revisit this for Spring 3.1. For the time being, in Spring 3.0, you'll have to configure an AnnotationMethodHandlerAdapter bean, passing a ConfigurableWebBindingInitializer into its "webBindingInitializer" property. That nested ConfigurableWebBindingInitializer bean in turn features "conversionService" and "validator" properties. Juergen
          Hide
          whardwick whardwick added a comment -

          It would be nice to see this revisited now that 3.1 has been released.

          Show
          whardwick whardwick added a comment - It would be nice to see this revisited now that 3.1 has been released.
          Hide
          jianyu Tang Jianyu added a comment -

          I still need to use the workaround in version 3.1.2, voted for fixing

          Show
          jianyu Tang Jianyu added a comment - I still need to use the workaround in version 3.1.2, voted for fixing
          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          There are no plans anymore for configuration improvements in Spring Portlet MVC. We'll maintain our current arrangement for 4.3.x still but will drop Portlet MVC support entirely as of Spring 5.0, in favor of the upcoming Portlet API 3.0 which introduces its own mapping model.

          Show
          juergen.hoeller Juergen Hoeller added a comment - There are no plans anymore for configuration improvements in Spring Portlet MVC. We'll maintain our current arrangement for 4.3.x still but will drop Portlet MVC support entirely as of Spring 5.0, in favor of the upcoming Portlet API 3.0 which introduces its own mapping model.

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              alex.landini Alex Landini
              Last updater:
              Juergen Hoeller
            • Votes:
              15 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                31 weeks, 3 days ago