问题
I created validation messages(ValidationMessages.properties) file to make the i18n possible in my project.
It looks like:
pwtNumber.error=PWT Number error..
I defined it in faces-config.xml:
<message-bundle>com.mycompany.web.i18n.ValidationMessages</message-bundle>
In my code I used it in this way:
@Null(message = "{pwtNumber.error}")
public String getPwtNummer() {
return pwtNummer;
}
But the problem is i don't get the error message but the key from the properties file. It is the error message that i get:
myForm:pwtNummer: {pwtNumber.error}
How can i solve it?
回答1:
You're confusing JSF builtin validation with JSR303 bean validation.
The <message-bundle> is to be used to override/specify JSF builtin validation messages, not JSR303 bean validation messages. Although you used the right filename for the JSR303 bean validation bundle file, ValidationMessages.properties, the JSR303 bean validation however also requires the bundle file to be placed in the root of the classpath (thus, without any package; in the default package). After you've fixed that, don't forget to remove the incorrect <message-bundle> entry.
See also:
- Internationalization in JSF, when to use message-bundle and resource-bundle?
- Localization with bean validation in JSF
来源:https://stackoverflow.com/questions/12280800/how-does-it-work-with-bean-validation-messages-and-i18n-in-jsf2