Hibernate 验证在 JSF 2 中不显示自定义错误消息
我正在使用带有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 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.