不带格式和字段名称前缀的Jsr303 Bean验证错误消息 [英] Jsr303 Bean Validation error message without prefix of form and field name

查看:277
本文介绍了不带格式和字段名称前缀的Jsr303 Bean验证错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用bean验证和extval验证. 我在类路径中创建了一个名为ValidationMessages.properties的属性文件.在此文件中,我自定义了defult消息,

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 ,

例如: javax.validation.constraints.Size.message=this is a test messgae

在验证字段时,我可以看到我输入的消息,但问题是我还可以在消息'之前看到字段和表单名称,如下所示:formName:fieldName this is a test.
我要删除此前缀.当它是一个jsf验证时,我知道我需要添加javax.faces.validator.BeanValidator.MESSAGE属性,但是在这里它不起作用.

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?

更新: 如何覆盖两者 bean验证和jsf默认错误消息? (以及删除邮件之前的表单前缀和文件名) 我有ValidationMessages.properties表示bean消息,而messages.properties表示jsf验证.我需要在config-xmlweb.xml文件中定义什么?以及我在哪里放置javax.faces.validator.BeanValidator.MESSAGE属性?

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?

这对我来说非常重要

将提供任何帮助

感谢提前.

推荐答案

您在哪个文件中指定了javax.faces.validator.BeanValidator.MESSAGE属性?

In which file did you specify the javax.faces.validator.BeanValidator.MESSAGE property?

该属性必须在JSF已知的资源束中定义(例如,在faces-config.xml中注册的束),而不是在ValidationMessages.properties中.

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.

如果您不想显示组件标签,而仅显示约束违反消息,则属性值必须为{0}(javax.faces.validator.BeanValidator.MESSAGE={0}).可以在JSF 2规范的3.5.6.3节中找到更多信息.

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.

这篇关于不带格式和字段名称前缀的Jsr303 Bean验证错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆