Hibernate 验证在 JSF 2 中不显示自定义错误消息

发布于 2024-12-13 11:36:42 字数 956 浏览 6 评论 0原文

我正在使用带有 JSF 2 和 Spring 的 hibernate 验证(4.2.0 Final) 这是我的配置:

1- applicationContext:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
    <list>

    <value>classpath:messages/ValidationMessages</value>
    <value>classpath:messages/application</value>

    </list>
    </property>
    <property name="defaultEncoding" value="UTF-8"/>
    </bean> 

2- faces-config.xml:

<resource-bundle>
           <base-name>messages.ValidationMessages</base-name>
        </resource-bundle>

当尝试使用以下内容时:

@NotBlank(message = "{name.required}")
private String name;

它不起作用,它不显示来自属性文件的消息,它显示 {name.required}

请告知为什么它不起作用。

i am using hibernate validation (4.2.0 Final) with JSF 2 and Spring
and here's my configuration:

1- applicationContext:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
    <list>

    <value>classpath:messages/ValidationMessages</value>
    <value>classpath:messages/application</value>

    </list>
    </property>
    <property name="defaultEncoding" value="UTF-8"/>
    </bean> 

2- faces-config.xml:

<resource-bundle>
           <base-name>messages.ValidationMessages</base-name>
        </resource-bundle>

when trying to use the following:

@NotBlank(message = "{name.required}")
private String name;

it doesn't work, it doesn't display the message from property file, it displays {name.required}

please advise why it's not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2024-12-20 11:36:42

问题是 ValidationMessages.properties 不是直接在类路径下,我将它放在类路径中的消息文件夹中,当我将它直接移动到类路径下时它可以工作现在好了。

problem was that ValidationMessages.properties is not under the classpath directly, i was putting it inside a messages folder in the classpath, when i moved it to be under classpath directly it works fine now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文