tags:

views:

17

answers:

1

I want to get message.properties's message as a String in Java.

How can I get it?

A: 

If it is definied as a message-bundle of the application in faces-config.xml like follows

<application>
    <message-bundle>messages</message-bundle>
</application>

then you can get its name by Application#getMessageBundle()

String messageBundleName = facesContext.getApplication().getMessageBundle();

This way you can get its ResourceBundle instance as follows:

ResourceBundle messageBundle = ResourceBundle.getBundle(messageBundleName);

Finally you can get a message property by key as follows:

String value = messageBundle.getString("property.key");

See also:

BalusC