How can I get a message.properties entry as a string for bean support?

I need to get message.properties message as String with bean support.

How can i achieve this?

+3
source share
1 answer

If it is defined as message-bundle application in faces-config.xml as follows

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

then you can get its name Application#getMessageBundle()

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

This way you can get a ResourceBundle instance as follows:

 ResourceBundle messageBundle = ResourceBundle.getBundle(messageBundleName); 

Finally, you can get the message property by key as follows:

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

All Articles