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 3978548
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:03:40+00:00 2026-05-20T05:03:40+00:00

I have this bean: @ManagedBean(name=langListing) @ViewScoped public class LangListing implements Serializable { private List<SelectItem>

  • 0

I have this bean:

@ManagedBean(name="langListing")
@ViewScoped
public class LangListing implements Serializable
{
    private List<SelectItem> languages = new ArrayList<SelectItem>();
    private String language;

    public LangListing() {
       createLangs(); // lazy loading
    }   

    public void createLangs()
    {   
       languages.add(new SelectItem("en", FacesUtil.getResourceBundle().getString("LANG_LABEL_01"))); // English
       languages.add(new SelectItem("fr", FacesUtil.getResourceBundle().getString("LANG_LABEL_02"))); // French
    }

    public List<SelectItem> getLanguages() { 
       return languages;
    }

    public String getLanguage()
    {
       if (FacesContext.getCurrentInstance().getViewRoot().getLocale() != null) {
          language = FacesContext.getCurrentInstance().getViewRoot().getLocale().toString();
       } else {
          language = "en";
       }

       return language;
    }

    public void setLanguages(List<SelectItem> languages) {
       this.languages = languages;
    }    

    public void setLanguage(String language) {
       this.language = language;
    }

    public void changeLocale(AjaxBehaviorEvent event) {
       FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(getLanguage()));
    }
 } 

I’m calling the bean methods from:

<h:selectOneMenu id="selectLang" immediate="true" value="#{langListing.language}">
    <f:ajax listener="#{langListing.changeLocale}" render="@form" />
    <f:selectItems value="#{langListing.languages}" />
</h:selectOneMenu>

The problem is I can’t get the codes to change locale from English to French. Can anyone see the problem? Please help.

  • 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-20T05:03:41+00:00Added an answer on May 20, 2026 at 5:03 am

    You’re setting it with the value of getLanguage() which returns the current UIViewRoot locale or otherwise just en. It does not return the selected language value.

    You need to revise the logic in your bean. Here’s a rewrite:

    @ManagedBean(name="langListing")
    @ViewScoped
    public class LangListing implements Serializable {
        private List<SelectItem> languages = new ArrayList<SelectItem>();
        private String language;
    
        public LangListing() {
           languages.add(new SelectItem("en", FacesUtil.getResourceBundle().getString("LANG_LABEL_01"))); // English
           languages.add(new SelectItem("fr", FacesUtil.getResourceBundle().getString("LANG_LABEL_02"))); // French
           language = FacesContext.getCurrentInstance().getViewRoot().getLocale().toString();
        }   
    
        public List<SelectItem> getLanguages() { 
           return languages;
        }
    
        public String getLanguage() {
           return language;
        }
    
        public void setLanguages(List<SelectItem> languages) {
           this.languages = languages;
        }    
    
        public void setLanguage(String language) {
           this.language = language;
        }
    
        public void changeLocale(AjaxBehaviorEvent event) {
           FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(language));
        }
     } 
    

    Note that there are more potential flaws/holes with this approach. The bean is view scoped instead of session scoped and you don’t seem to be using <f:view> (since that expects a Locale, not String). I’d warmly recommend to get yourself through this answer to align it out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Session scoped bean @SessionScoped public class UserData implements Serializable { private
I have a JSF 2.0 bean: @ManagedBean @SessionScoped public class LoginBean implements Serializable {
I have a view-scoped bean ManageFoo.java: @ManagedBean(name = ManageFoo) @ViewScoped public class ManageFoo {
i have an managed bean(session scope) like this: class Home {// as homeBean public
I have this Spring config: <bean id=boo class=com.x.TheClass/> The class TheClass implements TheInterface .
I have a custom converter which is this : @ManagedBean @RequestScoped public class MeasureConverter
I have this managed bean which takes two values from database's table import java.io.Serializable;
I have this managed bean based on this tutorial . import java.io.Serializable; import javax.enterprise.context.SessionScoped;
I have a session bean <managed-bean> <managed-bean-name>vdcAddBean</managed-bean-name> <managed-bean-class>com.cloud.appsportfolio.jsf.vdc.beans.VDCAddBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> Now, I am injecting
I have this problem, in a form I have a list of customers that

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.