title: How to change the view locale by p:commandLinks?
body: <p>I'm trying to implement internationalization in JSF 2. I've tried many solutions, but I'm not able to make it to change the view locale. Here is my code for <code>faces-config.xml</code> file:</p>
  
  <pre><code>&lt;application&gt;
      &lt;locale-config&gt;
          &lt;default-locale&gt;es&lt;/default-locale&gt;
          &lt;supported-locale&gt;en_GB&lt;/supported-locale&gt;
          &lt;supported-locale&gt;fr&lt;/supported-locale&gt;
      &lt;/locale-config&gt;
      &lt;resource-bundle&gt;
          &lt;base-name&gt;malagaAcoge.configuracion.Messages&lt;/base-name&gt;
          &lt;var&gt;msg&lt;/var&gt;
      &lt;/resource-bundle&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>I'm using 3 properties that are located into my source package.</p>
  
  <p>This is my view:</p>
  
  <pre><code>&lt;f:view locale="#{idiomaBean.locale}"&gt;
      &lt;div id="contenedor"&gt;
          &lt;div id="cabecera"
              style="background: url('../images/logo/fondoCabecera.png') no-repeat"&gt;
          &lt;/div&gt;
          &lt;div id="cuerpo"&gt;
              &lt;div id="center"&gt;
                  &lt;h:form prependId="false" id="form_login"&gt;
                      &lt;h:selectOneMenu value="#{idiomaBean.locale}"
                          onchange="submit()"
                          valueChangeListener="#{idiomaBean.changeLanguage}"&gt;
                          &lt;f:selectItems value="#{idiomaBean.countriesInMap}" /&gt;
                      &lt;/h:selectOneMenu&gt;
  
                      &lt;h:panelGrid columns="3"&gt;
                          &lt;p:commandLink title="SP" action="#{idiomaBean.changeLanguage}"&gt;
                              &lt;p:graphicImage value="../images/paises/sp.png"&gt;&lt;/p:graphicImage&gt;
                          &lt;/p:commandLink&gt;
                          &lt;p:commandLink title="EN" action="#{idiomaBean.changeLanguage}"&gt;
                              &lt;p:graphicImage value="../images/paises/en.png"&gt;
                              &lt;/p:graphicImage&gt;
                          &lt;/p:commandLink&gt;
                          &lt;p:commandLink title="FR" action="#{idiomaBean.changeLanguage}"&gt;
                              &lt;p:graphicImage value="../images/paises/fr.png"&gt;
                              &lt;/p:graphicImage&gt;
                              &lt;f:setPropertyActionListener target="#{idiomaBean.locale}"
                                  value="fr"&gt;&lt;/f:setPropertyActionListener&gt;
                          &lt;/p:commandLink&gt;
                      &lt;/h:panelGrid&gt;
  </code></pre>
  
  <p>This is the <code>IdiomaBean</code> I'm using to perform the change:</p>
  
  <pre><code>private static final long serialVersionUID = 1L;
  private static String locale = FacesContext.getCurrentInstance()
          .getViewRoot().getLocale().getLanguage();
  private static Map&lt;String, Object&gt; countries;
  static {
      countries = new LinkedHashMap&lt;String, Object&gt;();
      countries.put("Español", new Locale("es")); // label, value
      countries.put("English", Locale.ENGLISH);
      countries.put("Français", Locale.FRENCH);
  }
  
  public Map&lt;String, Object&gt; getCountriesInMap() {
      return countries;
  }
  
  public String getLocale() {
      return locale;
  }
  
  @SuppressWarnings("static-access")
  public void setLocale(String locale) {
      this.locale = locale;
      FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(locale));
  }
  
  public void changeLanguage(ValueChangeEvent e) {
      String newLocaleValue = e.getNewValue().toString();
  
      // loop country map to compare the locale code
      for (Map.Entry&lt;String, Object&gt; entry : countries.entrySet()) {
  
          if (entry.getValue().toString().equals(newLocaleValue)) {
  
              FacesContext.getCurrentInstance().getViewRoot()
                      .setLocale((Locale) entry.getValue());
  
          }
      }
  </code></pre>
  
  <p>I'm using PrimeFaces 3.0 on Tomcat server.</p>