简体   繁体   中英

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

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM