The largest Interview Solution Library on the web

« Previous | 1 | 2 | 3 | Next »


Internationalization is a technique in which status messages, GUI component labels, currency, date are not hardcoded in the program instead they are stored outside the source code in resource bundles and retrieved dynamically. JSF provide a very convenient way to handle resource bundle.

Following steps are required to internalize a JSF application

Step 1. Define properties files

Create properties file for each locale. Name should be in <file-name>_<locale>.properties format.

Default locale can be omitted in file name.

greeting=Hello World!

greeting=Bonjour tout le monde!

Step 2. Update faces-config.xml



Step 3. Use resource-bundle var


&lr;h:outputText value="#{msg['greeting']}" />

Example Application

Let us create a test JSF application to test internationalization in JSF.
1Create a project with a name helloworld under a package com.javatechnologycenter.test as explained in the JSF - First Application chapter.
2Create resources folder under src > main folder.
3Create com folder under src > main > resources folder.
4Create javatechnologycenter folder under src > main > resources > com folder.
5Create file under src > main > resources > com > javatechnologycenterfolder.Modify it as explained below
6Create file under src > main > resources > com > javatechnologycenterfolder.Modify it as explained below
7Create faces-config.xml in WEB-INF folder as explained below.
8Create under package com.javatechnologycenter.test as explained below.
9Modify home.xhtml as explained below. Keep rest of the files unchanged.
10Compile and run the application to make sure business logic is working as per the requirements.
11Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver.
12Launch your web application using appropriate URL as explained below in the last step.

greeting=Hello World!

greeting=Bonjour tout le monde!


<?xml version="1.0" encoding="UTF-8"?>

package com.javatechnologycenter.test;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
@ManagedBean(name = "userData", eager = true)
public class UserData implements Serializable {
private static final long serialVersionUID = 1L;
private String locale;
private static Map<String,Object> countries;
countries = new LinkedHashMap<String,Object>();
countries.put("English", Locale.ENGLISH);
countries.put("French", Locale.FRENCH);
public Map<String, Object> getCountries() {
return countries;
public String getLocale() {
return locale;
public void setLocale(String locale) {
this.locale = locale;
//value change event listener
public void localeChanged(ValueChangeEvent e){
String newLocaleValue = e.getNewValue().toString();
for (Map.Entry<String, Object> entry : countries.entrySet()) {


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
<title>JSF tutorial</title>
<h2>Internalization Language Example</h2>
<h3><h:outputText value="#{msg['greeting']}" /></h3>
<h:panelGrid columns="2">
Language :
<h:selectOneMenu value="#{userData.locale}" onchange="submit()"
<f:selectItems value="#{userData.countries}" />
Once you are ready with all the changes done, let us compile and run the application as we did in JSF - First Application chapter. If everything is fine with your application, this will produce following result:

Change language from dropdown. You will see the following output.
« Previous | 1 | 2 | 3 | Next »

copyright © 2014 - all rights riserved by