4

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>
4
  • Do you have a validation_pt.properties file with the correct keys? Commented Mar 5, 2013 at 13:20
  • yes, using 2 locales en and pt in this case default locale is pt. Commented Mar 5, 2013 at 13:26
  • my result message is {news.title.error} in view: <form:errors path="*" cssClass="alert alert-error" element="div"/> Commented Mar 5, 2013 at 13:59
  • yes file are correct. Commented Apr 24, 2013 at 13:50

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.