我的问题基本上和Custom validation message for bean validation一样。然而,我不能解决这个问题。
bean类:
public class PersonalInfoBean {
@Size(min=5, max=55, message="{invalid_name}")
String name;
...
}我在Eclipse项目的src文件夹中的一个包中创建了Messages.properties。
invalid_name=Please enter a valid name我在faces-config.xml中注册了该文件:
<application>
<message-bundle>com.webage.survey.Messages</message-bundle>
</application>facelet文件包含:
<h:inputText value="#{personalInfo.name}" id="name"/> <h:message for="name" style="color: red" /><br/>当我提交表单时,我只看到{invalid_name}作为错误消息,而没有看到“请输入有效名称”。
我在JBoss 6和WebSphere 8上进行了测试,结果相同。
发布于 2012-04-28 03:52:20
您正在将JSR 303 Bean Validation framework与JSF内置验证混合在一起。JSR 303Bean验证框架不是JSF框架的一部分。它是一个完全独立的验证框架,JSF恰好有对它的集成支持。
您需要在不同的属性文件中指定JSR303Bean验证消息,而不是使用可以使用ValidationMessages_xx_XX.properties文件本地化的确切文件名ValidationMessages.properties。这些文件必须放在类路径的根目录中。
您不需要在faces-config.xml中注册它。<message-bundle>仅用于required="true"、<f:validateRegex>、<f:convertDateTime>等JSF内置转换器和验证器。
https://stackoverflow.com/questions/10356949
复制相似问题