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

  • SEARCH
  • Home
  • 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 5949105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:12:08+00:00 2026-05-22T17:12:08+00:00

In my WebApp I created a managed Bean that allows me to change the

  • 0

In my WebApp I created a managed Bean that allows me to change the Locale from French to english and vice versa using Event Change Listener.

      package beans;

    import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class LocaleBean {

    private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

    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);
    }

}

and in my template.xhtml:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="#{localeBean.language}"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui" 
      xmlns:f="http://java.sun.com/jsf/core">
    <f:view contentType="text/html" locale="#{localeBean.locale}"  id="mescoca">
        <h:head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title><ui:insert name="title"></ui:insert></title>
            <h:outputStylesheet name="css/jsfcrud.css"/>
            <!--<f:loadBundle var="bundle" basename="/Bundle"/> -->
        </h:head>

        <h:body style="font-size: small; font-family: Ubuntu,verdana;">
          <h:form>
     <p:panel closable="false" style="float: right;height: 50px;font-size: smaller" >
     <h:panelGrid columns="2" style="text-align: center">
       <h:outputText value="#{bundle.Language}"/>
       <h:selectOneMenu value="#{localeBean.language}"                                 onchange="submit()">
     <f:selectItem itemValue="fr" itemLabel="Français" />
      <f:selectItem itemValue="en" itemLabel="English" />
       <f:selectItem itemValue="fr_FR" itemLabel="France"/>
        <f:selectItem itemValue="en_US" itemLabel="US" />
     </h:selectOneMenu>
        </h:panelGrid>
      </p:panel>

The others pages:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.EditHistoryTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body" >
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form>.....

It is working, but the problem is that the language gets back to its first value once I navigate to another page. Otherwise, When I change the language, it only affects the current page and once I move to another page, the localization bundle gets its default value in faces-config.xml

What I need is to make the language persistent through the whole session.
Does anyone have a clue plz?

  • 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-22T17:12:08+00:00Added an answer on May 22, 2026 at 5:12 pm

    You need to wrap your master template in a

    <f:view locale="#{LanguageBean.localeCode}">
    

    See also:

    • Localization in JSF, how to remember selected locale per session instead of per request/view – contains complete bean/view code example
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a webapp using CodeIgniter that requires authentication. I created a model
I have created a webapp using maven2 archetype in netbeans 6.7. when I do
I have a webapp created using C# and asp.net. I placed a parameter value
I'm currently working on a small webapp where I work. I've created this for
I have created a web application using Jersey and Dynamic Web Project of Eclipse.
we have a C++ Win32 DLL that reads data from Excel. The application uses
Due project requirements, I need to create a webapp that, when executing, will allow
I am writing a MVC 3 WebApp which uses XRM 2011 using Early Bound.
I'm trying to use Cargo to manage containers from a webapp on the same
I'm using IIS and trying to deploy a web application that needs authentication mode=Windows.

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.