This article was last updated on : November 4th, 2016 at 10:36 am

Tutorial : properties file in JSF with example

Message or Properties file in JSF

Objective of Example : Using .properties File in JSF :
1. In this example we will demonstrate how to use .properties or message file in jsf.
2. The idea behind using properties or message files in JSF is write one place use anywhere in application.
3. Eclipse Hierarchy of this project is given below.

Image to show eclipse architecture how to load properties file in JSF
“properties file in JSF Dynamic Web Project

Please follow the below steps to do this using properties or resource bundle file in JSF.

1. Create A JSF Dynamic Web Project in Eclipse :
Please create a JSF dynamic web project with name “UsingPropertiesFileInJSF”.
Please see this tutorial “How to create Dynamic web Application in JSF”.

2. Create JSP pages for this project :
Now we have to create two JSP pages.
1. usingResourceBundle.jsp – To use a properties file in JSP page we use

2. – This is the properties files where we will store the messages. It will be in key-value format. Inside the JSF page we will use the key to find the value.
Please see in JSP page basename=”com.sitenol.messageBundle.messageBundle” so after compilation After compilation of this web project file should be in folder –

label_greeting = Welcome to
label_current_year=Current Year is 2013.
label_java_j2ee_technologies=Core Java, Servlet, JSP, JSF.

2. usingResourceBundle.jsp

<[email protected] import="java.util.Calendar"%>
<[email protected] import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<[email protected] uri="" prefix="h"%>
<[email protected] uri="" prefix="f"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Using Message or Resource Bundle in JSF</title>
		<f:loadBundle var="msgs"
			basename="com.sitenol.resourceBundle.messageBundle" />
		<h:panelGrid columns="1" border="0">
			<h:outputText value="#{msgs.label_greeting}"
				style="text-color : red;"></h:outputText>
				<h:outputText value="#{msgs.label_current_year}"></h:outputText>
			<h:outputText value="#{msgs.label_java_j2ee_technologies}"></h:outputText>

3. Create faces-config.xml file :
Please find the faces-config.xml file code here. This faces-config.xml file is for example using .properties file in JSF.


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

4. Create web.xml file :
Please find the web.xml file code here. This web.xml file is for example using .properties file in JSF.


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xmlns:web="" xsi:schemaLocation="" id="WebApp_ID" version="2.5">
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-name>Faces Servlet</servlet-name>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
	This parameter tells MyFaces if javascript code should be allowed in
	the rendered HTML output.
	If javascript is allowed, command_link anchors will have javascript code
	that submits the corresponding form.
	If javascript is not allowed, the state saving info and nested parameters
	will be added as url parameters.
	Default is 'true'</description>
	If true, rendered HTML code will be formatted, so that it is 'human-readable'
	i.e. additional line separators and whitespace will be written, that do not
	influence the HTML code.
	Default is 'true'</description>
	If true, a javascript function will be rendered that is able to restore the
	former vertical scroll on every request. Convenient feature if you have pages
	with long lists and you do not want the browser page to always jump to the top
	if you trigger a link or button action that stays on the same page.
	Default is 'false'

5. Create War and Deploy Application to Server :
In this step we will create war with name UsingPropertiesFileInJSF.war . Please deploy this war file to web application server. After the please start the web application server.

6. Run The Application :
After successfully war deployment. Please start the server. After that open Internet Explorer and hit this “http://localhost:8080/UsingPropertiesFileInJSF/usingResourceBundle.faces”.
So now we can see output of message or resource bundle example in JSF.
Out put screen will be like this

Image showing output screen for JSF properties file tutorial
output : using .properties file in JSF

Share this post:

Related Posts

Leave a Comment