---
title: "JSF1.2 在程序中得到reource中的值"
author: "iamlibo"
date: "2007-08-08T10:38:00Z"
tags: []
slug: "jsf1-2-reource"
draft: false
lastmod: "2007-08-08T10:38:00Z"
id: 274405
url: "https://iamlibo.iteye.com/blog/274405"
---

在JSF1.2的bean或其他java代码中想得到reources中帮定的国际资源的值可以通过下面的方法:

protected String getLocalMessages(String mesKey) {  
ResourceBundle bundle = getApplication().getResourceBundle(  
getFacesContext(), "resource");  
if (bundle != null)  
return bundle.getString(mesKey);  
return "";  
}

其中参数mesKey就是properties文件中的key.

"resource"是在faces-config.xml中配置的.

&lt;application&gt;  
&lt;resource-bundle&gt;  
&lt;base-name&gt;resources.resource&lt;/base-name&gt;  
&lt;var&gt;resource&lt;/var&gt;  
&lt;/resource-bundle&gt;  
&lt;locale-config&gt;  
&lt;default-locale&gt;cn&lt;/default-locale&gt;  
&lt;supported-locale&gt;en&lt;/supported-locale&gt;  
&lt;/locale-config&gt;  
&lt;/application&gt;  
&lt;/faces-config&gt;

"resource"就是&lt;var&gt;resource&lt;/var&gt;中的值.可以根据情况自已设置.

Technorati : [jsf1.2](http://technorati.com/tag/jsf1.2)