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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:58:15+00:00 2026-05-25T10:58:15+00:00

I’m wondering how internationalization works in jsf? I have read tutorial on coreservlets.com about

  • 0

I’m wondering how internationalization works in jsf? I have read tutorial on coreservlets.com about it, but in my case it works slightly differently. In that tutorial said that i have to use

FacesContext.getCurrentInstance().getViewRoot().setLocale(newLocale);

in actionListener(listener for changing locale) and also backing bean has to have property getCurrentLocale() to use it in <f:view> tag.

I have 2 property files with messages(default and with specified locale), they are registered in faces-config.xml. <f:view> tag I have only at one page(index.xhtml)

<f:view locale="#{bean.locale}">
...
</f:view>

Also I have 2 buttons(with actionListener) for each locale. In backing bean I simply modify current locale variable(don’t use getViewRoot().setLocale(newLocale)). But locale changes for all pages(even if they don’t have <f:view locale="#{bean.locale}">)

  • 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-25T10:58:15+00:00Added an answer on May 25, 2026 at 10:58 am

    Lets say you have following two messages files

        messages.properties
        messages_de.properties
    

    Setting the Application Locale

    There are three ways of setting the Application Locale and I think you need the first one here.

    1-You can let the browser choose the locale.

    Set the default and supported locales in WEB-INF/faces-config.xml:

    <faces-config>
       <application>
          <locale-config>
             <default-locale>en</default-locale>
             <supported-locale>de</supported-locale>
          </locale-config>
      </application>
    </faces-config>
    

    When a browser connects to your application, it usually includes an Accept-Language value in the HTTP header

    2-You can set the locale programatically.

    Call the setLocale method of the UIViewRoot object:

    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    viewRoot.setLocale(new Locale("de"));
    

    3-You can set the locale for an individual page

    By using the f:view element with a locale attribute—for example:

    <f:view locale="de">
    

    The locale can be dynamically set:

    <f:view locale="#{user.locale}"/>
    

    Declaring message bundles
    Now that the Locale is set you can use one of the following two ways to declare message bundles

    1-Via faces-config
    The simplest way is to supply a file named faces-config.xml in the WEB-INF directory of your application, with the following contents:

    <?xml version="1.0"?>
    <faces-config xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
       version="2.0">
       <application>
          <resource-bundle>
             <base-name>com.corejsf.messages</base-name>
             <var>msgs</var>
          </resource-bundle>
       </application>
    </faces-config>
    

    2-At each JSF page that needs access it.
    Instead of using a global resource bundle declaration, you can add the f:loadBundle element to each JSF page that needs access to the bundle, like this:

    <f:loadBundle basename="com.corejsf.messages" var="msgs"/>
    

    In either case, the messages in the bundle are accessible through a map variable with the name msgs.

    Showing appropriate label on button
    Now lets say default properties file i.e english has property

    next=Next
    

    and German has equivallent i.e

    next=Weiter
    

    And you have set the locale and declared mesg bundle you can access it to put the label on a command button like

    <h:commandButton value="#{msgs.next}"/>
    

    Above Answer is extracted and modified from Hortsmen Core Java Server Faces book.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
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 want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.