Spring MVC Portlet JSR-303 (Validation)


En el applicationContext de spring:
	<!-- Portlet annotations support -->
	<bean id="parameterMappingInterceptor"
		class="org.springframework.web.portlet.handler.ParameterMappingInterceptor" />

	<bean
		class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
		<property name="interceptors">
			<list>
				<ref bean="parameterMappingInterceptor" />
			</list>
		</property>
	</bean>

	<!-- mvc:annotation-driven @Valid JSR-303 -->
	<mvc:annotation-driven validator="validator" />
	<bean id="validator"
		class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
	<bean id="annotationMethodHandlerAdapter"
		class="org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="webBindingInitializer">
			<bean id="configurableWebBindingInitializer"
				class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
				<property name="validator">
					<ref bean="validator" />
				</property>
			</bean>
		</property>
	</bean>

	<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>classpath:Language</value>
				<value>classpath:ValidationMessages</value>
			</list>
		</property>
		<property name="defaultEncoding" value="UTF-8" />
	</bean>

En el pom.xml:

		<!-- Validation -->
		<dependency>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
			<version>1.0.0.GA</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
			<version>4.3.0.Final</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator-annotation-processor</artifactId>
			<version>4.3.0.Final</version>
		</dependency>

Hibernate Validator anotaciones ejemplo

Anuncios
Spring MVC Portlet JSR-303 (Validation)