JSF:Resourcebundle Problem with Internationalization

Posted by Sven on Stack Overflow See other posts from Stack Overflow or by Sven
Published on 2011-01-13T11:37:25Z Indexed on 2011/01/13 12:54 UTC
Read the original article Hit count: 411

Filed under:
|
|

I implemented internationalization like in that tutorial!

When I change the language in my app. It works. But only until the next request happens. Then language settings are reset to my standard language -.-

What am I missing here:

LanguageBean.java

@ManagedBean(name="language")
@SessionScoped
public class LanguageBean implements Serializable{

    private static final long serialVersionUID = 1L;

    private String localeCode;

    private static Map<String,Object> countries;
    static{
        countries = new LinkedHashMap<String,Object>();
        countries.put("Deutsch", Locale.GERMAN); //label, value
        countries.put("English", Locale.ENGLISH); 

    }

    public Map<String, Object> getCountriesInMap() {
        return countries;
    }

    public String getLocaleCode() {
        return localeCode;
    }


    public void setLocaleCode(String localeCode) {
        this.localeCode = localeCode;
    }

    //value change event listener
    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());

              }
        }
    }

}

my facelets template:

                <h:selectOneMenu value="#{language.localeCode}" onchange="submit()"
            valueChangeListener="#{language.countryLocaleCodeChanged}">
            <f:selectItems value="#{language.countriesInMap}" />
        </h:selectOneMenu>

faces-config:

<application>
           <locale-config>
                <default-locale>de</default-locale>
           </locale-config>
       <resource-bundle>
        <base-name>org.dhbw.stg.wwi2008c.mopro.ui.text</base-name>
        <var>msg</var>
       </resource-bundle>
     </application>

© Stack Overflow or respective owner

Related posts about jsf

Related posts about internationalization