【问题标题】:Override Hibernate Validator message覆盖休眠验证器消息
【发布时间】: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

我也尝试过:

  1. 将 ValidationMessages_de.properties 移至另一个目录
  2. 创建了 ValidationMessages.properties 以及 ValidationMessages_de_DE.properties

以上都不能解决问题。验证时,Hibernate 给我德国语言环境的默认消息:darf nicht leer sein

我错过了什么?

【问题讨论】:

标签: hibernate jsf hibernate-validator


【解决方案1】:

虽然我已将 faces-config.xml 配置为查看 translations,但由于某些原因它无法从资源中读取。

一旦我移动了 src\main\resources\ 下的文件,一切都开始工作了。

【讨论】:

  • 你配置了 faces-config,所以你告诉了 JSF。 Hibernate 仍然不知道。 AFAIK,无法为 Hibernate 配置此路径。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-31
  • 1970-01-01
  • 2020-01-17
  • 2018-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多