Jsr303 Bean Validation错误消息没有表单和字段名称的前缀
我正在使用 bean 验证和 extval 验证。 我在类路径中创建了一个名为 ValidationMessages.properties 的属性文件。在此文件中,我自定义了默认消息,
例如: javax.validation.constraints.Size.message=this is a test messagesgae
当验证字段时,我可以看到我写的消息,但问题是我之前还看到了字段和表单名称消息像这样:formName:fieldName 这是一个测试
。
我想删除这个前缀。当它是 jsf 验证时,我知道我需要添加 javax.faces.validator.BeanValidator.MESSAGE 属性,但在这里它不起作用。
我需要做什么才能删除此前缀并仅查看消息本身?
更新: 如何覆盖两者 bean 验证和 jsf 默认错误消息? (并删除消息前面的表单前缀和归档名称) 我有用于 bean 消息的 ValidationMessages.properties
和用于 jsf 验证的 messages.properties
。我需要在 config-xml 和 web.xml 文件中定义什么?我应该将 javax.faces.validator.BeanValidator.MESSAGE 属性放在哪里?
这对我来说非常非常重要,
任何帮助都会得到帮助,
提前致谢。
I'm using bean validation and extval validation.
I've created a properties file called ValidationMessages.properties
inside my class path. inside this file i customized the defult messages ,
for example:javax.validation.constraints.Size.message=this is a test messgae
when the fieild is being validated I can see the message I worte, but the problem is that I also see the field and form name before the message ' like this: formName:fieldName this is a test
.
I want to remove this prefix. when it's a jsf validation I know that i need to add javax.faces.validator.BeanValidator.MESSAGE
property, but here it does not work.
what do I need to do inorder to remove this prefix and to see only the message itself?
UPDATE:
How can I override both bean validation and jsf default error messages? (and also to delete the prefix of the form and filed name befor the message)
I have ValidationMessages.properties
for the bean messages and messages.properties
for the jsf validation. what do I need to define inside the config-xml
and the web.xml
files? and where do I put the javax.faces.validator.BeanValidator.MESSAGE
property?
this is very very important to me,
any help will be appriciated,
Thank's In Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在哪个文件中指定了 javax.faces.validator.BeanValidator.MESSAGE 属性?
该属性必须在 JSF 已知的资源包中定义(例如,在
faces-config.xml
中注册的资源包),而不是在ValidationMessages.properties
内。如果您不想显示组件标签,但属性值必须为
{0}
(javax.faces.validator.BeanValidator.MESSAGE={0}
)仅约束违反消息。更多信息可以在 JSF 2 规范的 3.5.6.3 节中找到。In which file did you specify the
javax.faces.validator.BeanValidator.MESSAGE
property?The property must be defined in a resource bundle known to JSF (e.g. a bundle registered in
faces-config.xml
), not withinValidationMessages.properties
.The property value must be
{0}
(javax.faces.validator.BeanValidator.MESSAGE={0}
) if you don't want to display the component labels, but the constraint violation message only. More information can be find in the JSF 2 spec, section 3.5.6.3.我想现在如果不尝试这个你已经解决了这个问题:-
在你的 .xhtml 页面中意味着你声明组件的地方,将 lable 属性设置为空白(“”)。这不会采用前缀值,只会显示错误消息。
对于输入文本字段,您需要进行一些验证,然后像这样使用
,只需尝试一下,我认为您的问题可能会得到解决。
I think now you have solved this thing if not try this :-
in your .xhtml page means where you declare the component, make the lable attribute to blank(""). This will not take the prefix value,only the error message will display.
For a input text field you want some validation then use like this
just try out with this, I think your problem may got resolve.