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>
你有正確的密鑰的'validation_pt.properties'文件? – Ralph 2013-03-05 13:20:32
是的,在這種情況下使用2個語言環境en和pt,默認語言環境是pt。 – claudsan 2013-03-05 13:26:35
我的結果消息是** {news.title.error} ** in view: '
' – claudsan 2013-03-05 13:59:47