0

I am using JSF 2.0 and Spring 3.0.2 and tomcat 7.0.14.0 as server. I have an issue with changing language of my site. All the codes are working well in my local server. But when I deploy on server, Language changes does not effect. Its automatically select Italy as a default language. when I click on another language,nothing is changes. Here is my bean code:

            @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("English", Locale.ENGLISH); //label, value

            countries.put("Italian", Locale.ITALIAN);
}

public LanguageBean() {
    countries = new LinkedHashMap<String,Object>();


            countries.put("English", Locale.ENGLISH); //label, value
            countries.put("Italian", Locale.ITALIAN);

}

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


public String getLocaleCode() {
    return localeCode;
}


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


    public void countryLocaleCodeChanged(ValueChangeEvent e){

    String newLocaleValue = e.getNewValue().toString();


    for (Map.Entry<String, Object> entry : countries.entrySet()) {
            System.out.println("newLocaleValue "+newLocaleValue+"\n entry.getValue().toString()"+entry.getValue().toString());
        if(entry.getValue().toString().equals(newLocaleValue)){

            FacesContext.getCurrentInstance()
                .getViewRoot().setLocale((Locale)entry.getValue());
                    FacesContext context = FacesContext.getCurrentInstance(); 
                    System.out.println("Default : "+context.getApplication().getDefaultLocale()); 

                    context.getApplication().setDefaultLocale((Locale)entry.getValue());


        }
    }

}

And this is the config.xml::

    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
    <resource-bundle>
        <base-name>com.mad_u.welcome</base-name>
        <var>msg</var>
    </resource-bundle>

Please give me some idea. Thanks in advance.

Rounak
  • 181
  • 2
  • 2
  • 19
  • this [thread1](http://stackoverflow.com/questions/4830588/jsf-locale-is-set-per-request-not-for-session), [thread2](http://www.coderanch.com/t/447920/JSF/java/JSF-Locale) will help you. – Chandra Sekhar Aug 01 '12 at 08:07

1 Answers1

0

I had the same problem. My properties files were like this:

  • message_en_US.properties
  • message_es_ES.properties
  • message_eu_ES.properties

It was working in my local server but uploading the web to my server the language change didn't work, so I changed this:

        countries.put("Castellano", new Locale("es"));
        countries.put("Euskara", new Locale("eu"));
        countries.put("English", new Locale("en")); 

<locale-config>
            <default-locale>es</default-locale>
            <supported-locale>es</supported-locale>
            <supported-locale>eu</supported-locale>
            <supported-locale>en</supported-locale>
        </locale-config>

and

  • message_en.properties
  • message_es.properties
  • message_eu.properties
Jose Maeso
  • 81
  • 1
  • 6