Jsf-internationalization
提供:Dev Guides
JSF-国際化
国際化は、ステータスメッセージ、GUIコンポーネントラベル、通貨、日付をプログラムにハードコーディングしない手法です。 代わりに、リソースバンドルのソースコードの外部に保存され、動的に取得されます。 JSFは、リソースバンドルを処理する非常に便利な方法を提供します。
JSFアプリケーションを内部化するには、次の手順が必要です。
ステップ1:プロパティファイルを定義する
各ロケールのプロパティファイルを作成します。 名前は<file-name> _ <locale> .properties形式である必要があります。
デフォルトのロケールはファイル名で省略できます。
messages.properties
messages_fr.properties
ステップ2:faces-config.xmlを更新する
faces-config.xml
ステップ3:リソースバンドル変数を使用する
home.xhtml
応用例
テストJSFアプリケーションを作成して、JSFの国際化をテストしましょう。
Step | Description |
---|---|
1 | Create a project with a name helloworld under a package com.finddevguides.test as explained in the JSF - First Application chapter. |
2 | Create resources folder under src → mai folder. |
3 | Create com folder under src → main → resources folder. |
4 | Create finddevguides folder under src → main → resources → com folder. |
5 | Create messages.properties file under src → main → resources → com → finddevguides folder. Modify it as explained below. |
6 | Create messages_fr.properties file under src → main → resources → com → finddevguides folder. Modify it as explained below. |
7 | Create faces-config.xml in WEB-INFf older as explained below. |
8 | Create UserData.java under package com.finddevguides.test as explained below. |
9 | Modify home.xhtml as explained below. Keep the rest of the files unchanged. |
10 | Compile and run the application to make sure the business logic is working as per the requirements. |
11 | Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver. |
12 | Launch your web application using appropriate URL as explained below in the last step. |
messages.properties
messages_fr.properties
faces-config.xml
UserData.java
home.xhtml
すべての変更を完了したら、JSF-最初のアプリケーションの章で行ったようにアプリケーションをコンパイルして実行します。 すべてがアプリケーションで問題ない場合、次の結果が生成されます。
ドロップダウンから言語を変更します。 次の出力が表示されます。