【发布时间】:2017-09-06 19:42:33
【问题描述】:
我尝试覆盖默认的 Hibernate Validator 消息但没有成功。我已经在为几个文本使用资源包,效果很好。问题在于验证器的消息。
详细说明:
我创建了以下文件:ValidationMessages_de.properties 并将其放在 \src\main\resources\translations\ValidationMessages_de.properties 下。该文件具有以下资源: org.hibernate.validator.constraints.NotBlank.message=值是必需的。 org.hibernate.validator.constraints.NotEmpty.message=值是必需的。
我的 faces-config.xml 有以下内容:
<application>
<locale-config>
<default-locale>de</default-locale>
<supported-locale>de</supported-locale>
</locale-config>
<resource-bundle>
<base-name>translations.messages</base-name>
<var>msg</var>
</resource-bundle>
<resource-bundle>
<base-name>translations.ValidationMessages</base-name>
<var>validMsgs</var>
</resource-bundle>
<message-bundle>
translations.ValidationMessages
</message-bundle>
</application>
为了验证,我使用以下注释: @NotEmpty @NotBlank
我也尝试过:
- 将 ValidationMessages_de.properties 移至另一个目录
- 创建了 ValidationMessages.properties 以及 ValidationMessages_de_DE.properties
以上都不能解决问题。验证时,Hibernate 给我德国语言环境的默认消息:darf nicht leer sein
我错过了什么?
【问题讨论】:
-
是否在您部署的应用程序中
-
是的。 Primefaces 客户端验证正在从此消息包中读取文本,没有任何问题。 Hibernate 验证器似乎有读取问题。
标签: hibernate jsf hibernate-validator