Two stupid questions about bean validation used in JSF:
-
How can I remove the prefix
form1:userName:from the output message?<h:message for="userName" />Which gets:
form1:userName: Please enter a valid username (5-20 characters)I‘d also like to translate the name
form1:userNametoUser Name, it’s easy to implement such translation but I can’t find where to build the message. -
I have a custom validator, say
@CreditCard, its default message is{foo.bar.BadCreditNumber}@interface CreditCard { String message() default "{foo.bar.BadCreditNumber}"; }And the message is defined in
foo/bar/ValidationMessages.propertiesin classpath. Now how can I make this properties file loaded in every page?
Concerning 1: The error message’s format depends on the property javax.faces.validator.BeanValidator.MESSAGE which must be specified in a resource bundle of the application like this:
The placeholder
{0}refers to the error message as created by the Bean Validation runtime,{1}refers to the component label. So if you don’t want to have the label within the message, just make sure that the placeholder{1}isn’t contained within that property value.More information can be found in the JSF 2 spec. section 3.5.6.3.
Concerning 2: It’s as BalusC is saying, just put
ValidationMessages.propertiesto the root of your classpath. More information can also be found in the Hibernate Validator reference guide.