Jsr303 Bean Validation error message without prefix of form and field name

两盒软妹~` 提交于 2019-12-25 01:48:49

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9019182/jsr303-bean-validation-error-message-without-prefix-of-form-and-field-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!