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

The Archive Base Latest Questions

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

faces-config.xml : <application> <locale-config> <default-locale>ru</default-locale> <supported-locale>ua</supported-locale> </locale-config> </application> In a bean action method, I’m

  • 0

faces-config.xml:

<application>
    <locale-config>
        <default-locale>ru</default-locale>
        <supported-locale>ua</supported-locale>
    </locale-config>
</application> 

In a bean action method, I’m changing the locale in the current view as follows:

FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale("ua"));

The problem is that ua Locale is applied, but only per request/view and not for session. Another request/view within the same session resets the locale back to default ru value.

How can I apply the locale for session?

  • 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-20T01:40:06+00:00Added an answer on May 20, 2026 at 1:40 am

    You need to store the selected locale in the session scope and set it in the viewroot in two places: once by UIViewRoot#setLocale() immediately after changing the locale (which changes the locale of the current viewroot and thus get reflected in the postback; this part is not necessary when you perform a redirect afterwards) and once in the locale attribute of the <f:view> (which sets/retains the locale in the subsequent requests/views).

    Here’s an example how such a LocaleBean should look like:

    package com.example.faces;
    
    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;
    
        @PostConstruct
        public void init() {
            locale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
        }
    
        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 here’s an example of the view should look like:

    <!DOCTYPE html>
    <html lang="#{localeBean.language}"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html">
    <f:view locale="#{localeBean.locale}">
        <h:head>
            <title>JSF/Facelets i18n example</title>
        </h:head>
        <h:body>
            <h:form>
                <h:selectOneMenu value="#{localeBean.language}" onchange="submit()">
                    <f:selectItem itemValue="en" itemLabel="English" />
                    <f:selectItem itemValue="nl" itemLabel="Nederlands" />
                    <f:selectItem itemValue="es" itemLabel="Español" />
                </h:selectOneMenu>
            </h:form>
            <p><h:outputText value="#{text['some.text']}" /></p>
        </h:body>
    </f:view>
    </html>
    

    Which assumes that #{text} is already configured in faces-config.xml as below:

    <application>
        <resource-bundle>
            <base-name>com.example.i18n.text</base-name>
            <var>text</var>
        </resource-bundle>
    </application>
    

    Note that <html lang> is not required for functioning of JSF, but it’s mandatory how search bots interpret your page. Otherwise it would possibly be marked as duplicate content which is bad for SEO.

    See also:

    • Maven and JSF webapp structure, where exactly to put JSF resources
    • Internationalization in JSF, when to use message-bundle and resource-bundle?
    • i18n with UTF-8 encoded properties files in JSF 2.0 application
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a JSF/XPages application starts it reads the faces-config.xml for managed beans, validators etc.
I have something like that: faces-config.xml <managed-bean> <managed-bean-name>aBean</managed-bean-name> <managed-bean-class>some.pack.Bean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> I have a
Summary The Faces Config Editor in Eclipse does not open when editing faces-config.xml. This
My h:commandLink doesn't work. I've got a navigation rule in the faces-config.xml and a
I am getting the following exception in my application. com.sun.faces.config.ConfigurationException: It appears the JSP
I have developed a simple facelet portlet. Changed the ViewHandler in the faces-config.xml as
To handle viewExpiredException in JSF, I coded <error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/error.html</location> </error-page> <session-config> <session-timeout>1</session-timeout> </session-config>
In face-configs.xml, <navigation-rule> <from-view-id>/login.jspx</from-view-id> <navigation-case> <from-outcome>failure</from-outcome> <to-view-id>/login.jspx?Error=InvalidUser</to-view-id> <redirect /> </navigation-case> </navigation-rule> When Login return
We are using the default Oracle ADF Faces 10g default skin. It looks super
I'm trying to deal with @javax.faces.bean.ManagedProperty but without success ! I've been following this

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.