Reputation: 7180
My question is basically same as Custom validation message for bean validation. However, I can't fix the problem.
The bean class:
public class PersonalInfoBean {
@Size(min=5, max=55, message="{invalid_name}")
String name;
...
}
I created Messages.properties in a package in the src folder of Eclipse project.
invalid_name=Please enter a valid name
I registered the file in faces-config.xml:
<application>
<message-bundle>com.webage.survey.Messages</message-bundle>
</application>
The facelet file has:
<h:inputText value="#{personalInfo.name}" id="name"/> <h:message for="name" style="color: red" /><br/>
When I submit the form, I see only {invalid_name} as error message and not "Please enter a valid name".
I tested this with JBoss 6 and WebSphere 8 with the same result.
Upvotes: 4
Views: 2076
Reputation: 1108782
You're mixing JSR 303 Bean Validation framework with JSF builtin validation. JSR 303 Bean Validation framework is not part of JSF framework. It's an entirely standalone validation framework for which JSF just happens to have integration support.
You need to specify the JSR 303 Bean Validation messages in a different properties file instead with the exact filename of ValidationMessages.properties
, which can be localized with ValidationMessages_xx_XX.properties
files. Those files have to be placed in the root of the classpath.
You do not need to register it in faces-config.xml
. The <message-bundle>
is only used for JSF builtin converters and validators such as required="true"
, <f:validateRegex>
, <f:convertDateTime>
, etc.
Upvotes: 4