2013-03-05 127 views
4

如何根据我的语言正确地获取消息验证,我得到的默认hibernate验证程序的返回值是mensage,而不是注释@NotEmpt中定义的消息。Spring MVC i18n Hibernate Validation

@Entity 
    public class News { 

     @Id 
     private Integer idNews; 

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

在我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> 
+0

你有正确的密钥的'validation_pt.properties'文件? – Ralph 2013-03-05 13:20:32

+0

是的,在这种情况下使用2个语言环境en和pt,默认语言环境是pt。 – claudsan 2013-03-05 13:26:35

+0

我的结果消息是** {news.title.error} ** in view: '' – claudsan 2013-03-05 13:59:47

回答