1

JDK1.6およびTomcat6.1でJSF2.0を使用しています

ライブ Web セッションが停止しないように、サーバーを再起動せずにプロパティ ファイルの値 (JSF リソース バンドルによって読み込まれる) を更新する必要があります。

JDK1.6 で可能ですか。以下の clearCache コードを試しましたが、機能しませんでした。

ResourceBundle bundle = ResourceBundle.getBundle("Label");
String s = bundle.getString("profile.firstName");
out.println("Value before: %"+ s);
ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());
bundle = ResourceBundle.getBundle("Label");
s = bundle.getString("profile.firstName");
out.println("Value after: {}"+s);

誰かが前に同じことを試みましたか。

アップデート

以下は、リソースバンドルのリロードの問題を解決していないようです

ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());
ApplicationResourceBundle applicationBundle = ApplicationAssociate.getCurrentInstance().getResourceBundles().get("Label");
Field field = applicationBundle.getClass().getDeclaredField("resources");
field.setAccessible(true);
Map<Locale, ResourceBundle> resources = (Map<Locale, ResourceBundle>) field.get(applicationBundle);
resources.clear();

何か不足していますか?

4

1 に答える 1

3

これは、一部の JSF 実装/バージョンで機能していました。ただし、最近の Mojarra バージョンでは、キャッシング メカニズムの実装自体に追加のレイヤーが追加されました。実際にMojarraを使用していると仮定すると、行に加えて

ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());

また、これを行う必要があります。com.sun.faces.application.ApplicationAssociate

ApplicationResourceBundle applicationBundle = ApplicationAssociate.getCurrentInstance().getResourceBundles().get("Label");
Field field = applicationBundle.getClass().getDeclaredField("resources");
field.setAccessible(true);
Map<Locale, ResourceBundle> resources = (Map<Locale, ResourceBundle>) field.get(applicationBundle);
resources.clear();

はい、それはハックですが、JSF が同じことを達成するためのクリーンな API メソッドを提供していない限りです。

于 2011-03-30T19:59:35.747 に答える