本文介绍了如何在后备bean中以字符串形式获取message.properties的条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在后备bean中将message.properties
的消息作为String
接收.
I need to get message.properties
's message as a String
in backing bean.
我该如何实现?
推荐答案
如果将其定义为faces-config.xml
中application
的message-bundle
,如下所示
If it is definied as a message-bundle
of the application
in faces-config.xml
like follows
<application>
<message-bundle>messages</message-bundle>
</application>
然后您可以通过 Application#getMessageBundle()
then you can get its name by Application#getMessageBundle()
String messageBundleName = facesContext.getApplication().getMessageBundle();
通过这种方式,您可以获取其 ResourceBundle
实例如下:
This way you can get its ResourceBundle
instance as follows:
ResourceBundle messageBundle = ResourceBundle.getBundle(messageBundleName);
最后,您可以按如下所示通过键获取message属性:
Finally you can get a message property by key as follows:
String value = messageBundle.getString("property.key");
这篇关于如何在后备bean中以字符串形式获取message.properties的条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!