Skip to content

Portlet MVC - <mvc:annotation-driven /> doesn't inject conversion service and validator in WebDataBinder [SPR-6817] #11483

@spring-projects-issues

Description

@spring-projects-issues

Alex Landini opened SPR-6817 and commented

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:p="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:p="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);                   
    
}

Affects: 3.0 GA

Issue Links:

15 votes, 12 watchers

Metadata

Metadata

Assignees

Labels

has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importin: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions