Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:47:14+00:00 2026-05-27T05:47:14+00:00

I’m trying to implement internationalization in JSF 2. I’ve tried many solutions, but I’m

  • 0

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 faces-config.xml file:

<application>
    <locale-config>
        <default-locale>es</default-locale>
        <supported-locale>en_GB</supported-locale>
        <supported-locale>fr</supported-locale>
    </locale-config>
    <resource-bundle>
        <base-name>malagaAcoge.configuracion.Messages</base-name>
        <var>msg</var>
    </resource-bundle>
</application>

I’m using 3 properties that are located into my source package.

This is my view:

<f:view locale="#{idiomaBean.locale}">
    <div id="contenedor">
        <div id="cabecera"
            style="background: url('../images/logo/fondoCabecera.png') no-repeat">
        </div>
        <div id="cuerpo">
            <div id="center">
                <h:form prependId="false" id="form_login">
                    <h:selectOneMenu value="#{idiomaBean.locale}"
                        onchange="submit()"
                        valueChangeListener="#{idiomaBean.changeLanguage}">
                        <f:selectItems value="#{idiomaBean.countriesInMap}" />
                    </h:selectOneMenu>

                    <h:panelGrid columns="3">
                        <p:commandLink title="SP" action="#{idiomaBean.changeLanguage}">
                            <p:graphicImage value="../images/paises/sp.png"></p:graphicImage>
                        </p:commandLink>
                        <p:commandLink title="EN" action="#{idiomaBean.changeLanguage}">
                            <p:graphicImage value="../images/paises/en.png">
                            </p:graphicImage>
                        </p:commandLink>
                        <p:commandLink title="FR" action="#{idiomaBean.changeLanguage}">
                            <p:graphicImage value="../images/paises/fr.png">
                            </p:graphicImage>
                            <f:setPropertyActionListener target="#{idiomaBean.locale}"
                                value="fr"></f:setPropertyActionListener>
                        </p:commandLink>
                    </h:panelGrid>

This is the IdiomaBean I’m using to perform the change:

private static final long serialVersionUID = 1L;
private static String locale = FacesContext.getCurrentInstance()
        .getViewRoot().getLocale().getLanguage();
private static Map<String, Object> countries;
static {
    countries = new LinkedHashMap<String, Object>();
    countries.put("Español", new Locale("es")); // label, value
    countries.put("English", Locale.ENGLISH);
    countries.put("Français", Locale.FRENCH);
}

public Map<String, Object> 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<String, Object> entry : countries.entrySet()) {

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

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

        }
    }

I’m using PrimeFaces 3.0 on Tomcat server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:47:15+00:00Added an answer on May 27, 2026 at 5:47 am

    You’re not clear in your problem description. That dropdown list look like as it will work (although the value change listener is entirely superfluous), but those links indeed won’t work at all. I’m assuming that you’re actually asking how to implement the links properly.

    First, get rid of the value change listener method in both the dropdown list and the image links. You are not interested in the old value, you are only interested in the new value, so you don’t need it at all. As you’re using PrimeFaces 3.0 which in turn requires Servlet 3.0 which in turn comes along with EL 2.2, you should be able to just pass method arguments in EL. You only need to change Locale argument to String type so that it can also be used to pass as link method argument.

    Also, you should absolutely not make the user-selected locale static. It would going to be shared among all users in the same application. So if one user changes the locale, then every other visitor would see the last user-selected locale! Make it a non-static property of a session scoped bean instead.

    So, this should do

    <f:view locale="#{idiomaBean.locale}">
        <h:form>
            <h:selectOneMenu value="#{idiomaBean.language}" onchange="submit()">
                <f:selectItems value="#{idiomaBean.availableLanguages}" />
            </h:selectOneMenu>
    
            <h:panelGrid columns="3">
                <p:commandLink title="SP" action="#{idiomaBean.setLanguage('sp')}" update="@all">
                    <p:graphicImage value="../images/paises/sp.png" />
                </p:commandLink>
                <p:commandLink title="EN" action="#{idiomaBean.setLanguage('en')}" update="@all">
                    <p:graphicImage value="../images/paises/en.png" />
                </p:commandLink>
                <p:commandLink title="FR" action="#{idiomaBean.setLanguage('fr')}" update="@all">
                    <p:graphicImage value="../images/paises/fr.png" />
                </p:commandLink>
            </h:panelGrid>
        </h:form>
    </f:view>
    

    with

    @ManagedBean
    @SessionScoped
    public class IdiomaBean implements Serializable {
    
        private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    
        private static Map<String, String> availableLanguages;
    
        static {
            availableLanguages = new LinkedHashMap<String, String>();
            availableLanguages.put("Español", "es");
            availableLanguages.put("English", "en");
            availableLanguages.put("Français", "fr");
        }
    
        public Map<String, String> getAvailableLanguages() {
            return availableLanguages;
        }
    
        public Locale getLocale() {
            return locale;
        }
    
        public String getLanguage() {
            return locale.getLanguage();
        }
    
        public void setLanguage(String language) {
            locale = new Locale(language);
            FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.