Jsr303 Bean Validation错误消息没有表单和字段名称的前缀

发布于 2024-12-29 15:16:34 字数 751 浏览 4 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(2

老子叫无熙 2025-01-05 15:16:34

您在哪个文件中指定了 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 within ValidationMessages.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.

む无字情书 2025-01-05 15:16:34

我想现在如果不尝试这个你已经解决了这个问题:-
在你的 .xhtml 页面中意味着你声明组件的地方,将 lable 属性设置为空白(“”)。这不会采用前缀值,只会显示错误消息。

对于输入文本字段,您需要进行一些验证,然后像这样使用

<h:inputText id="abc" value="My Textbox" label="">

,只需尝试一下,我认为您的问题可能会得到解决。

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

<h:inputText id="abc" value="My Textbox" label="">

just try out with this, I think your problem may got resolve.

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