0

選択ボックスを使用して JSF アプリケーションのロケールを動的に変更しようとしています。しかし、faces-config.xml の設定を変更した場合にのみ、ロケールが変更されます。これで私を助けて..enter code here

<application>
           <locale-config>
                <default-locale>en</default-locale>
           </locale-config>
       <resource-bundle>
        <base-name>com.messages.messages_en</base-name>
        <var>msg</var>
       </resource-bundle>
     </application>

私の価値観チェンジリスナーは、

public void countryLocaleCodeChanged(ValueChangeEvent e){
        String newLocaleValue = e.getNewValue().toString();

        //loop country map to compare the locale code
                for (Map.Entry<String, Object> entry : countries.entrySet()) {

               if(entry.getValue().toString().equals(newLocaleValue)){

                FacesContext.getCurrentInstance()
                    .getViewRoot().setLocale((Locale)entry.getValue());

              }
               }
4

1 に答える 1

0

私は間違いを見つけました。問題は、faces-config.xml ファイルの設定にあります。正しい設定は次のとおりです。

<application>
           <locale-config>
            <supported-locale>en</supported-locale>                 
           <supported-locale>fr</supported-locale>
           </locale-config>
       <resource-bundle>
        <base-name>com.messages.messages</base-name>

        <var>msg</var>

       </resource-bundle>
     </application>

上記のコードでは、base-name はプロパティ ファイルの場所です。この例では、パッケージ名は com.messages で、プロパティ ファイルは messages です。ここでは、英語とフランス語の 2 つのロケールを使用しています。私が選択したデフォルトのロケールは English(en) です。ユーザーが選択したロケールに応じて、messages_en.properties または messages_fr.properties を取得します。

于 2013-11-06T05:17:06.153 に答える