claudsan
claudsan

Reputation: 195

Spring MVC i18n Hibernate Validation

how do I get the spring correctly the message validation according to my language, I am getting in return mensage the default hibernate validator but not the message that was defined in the annotation @NotEmpt.

    @Entity
    public class News {

        @Id
        private Integer idNews;

        @NotEmpty(message = "{news.title.error}")
        @Column
        private String title;
              ........
    }

in my configs:

<!-- locale change using a cookie -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" >
    <property name="defaultLocale" value="pt" />
</bean>

<!-- Access resource bundles with the specified basename -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>/WEB-INF/i18n/messages</value>
            <value>/WEB-INF/i18n/validation</value>
        </list>
    </property>
</bean>

<!-- JSR-303 -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <property name="validationMessageSource" ref="messageSource"/>
 </bean>

Upvotes: 4

Views: 3322

Answers (1)

Gentle Song
Gentle Song

Reputation: 90

your question maybe can be solved like this issue: https://jira.springsource.org/browse/SPR-8658?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

and the point is

change <mvc:annotation-driven /> to <mvc:annotation-driven validator="validator"/>

hope this can help you

Upvotes: 2

Related Questions