How does it work with bean validation messages and i18n in JSF2?

谁都会走 提交于 2019-12-01 15:25:11

问题


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

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