How to get context parameter values in JSF application

In this tutorial we are going to show you how to read web application context parameter values in your JSF application, in the bean Java code and straight in the XHTML view as well. Here are our sample application code snippets.

JSF get context param – web.xml

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

	<display-name>Reading context parameters sample</display-name>

	<!-- Context parameters -->
		<param-value>Simple parameter value</param-value>

	<!-- Welcome page -->

	<!-- Staring JSF -->
		<servlet-name>Faces Servlet</servlet-name>

	<!-- JSF URL mapping -->
		<servlet-name>Faces Servlet</servlet-name>


We add an context parameter named myParameter with the value of Simple parameter value in the web.xml application descriptor. This value is going to be read in our sample application.

JSF get context param – XHTML view code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns=""
        <title>Reading context params example</title>
    		<h2>Read the context parameter through bean</h2>
    		<h:outputText value="#{paramBean.contextParameter}"/>
    		<h2>Read the context parameter with the EL</h2>
    		<h:outputText value="#{initParam['myParameter']}"/>

In our xhtml sample view we output myParameter context parameter value using the h:outputText tag. At first we read the value from the bean – look a little bit lower for the details on reading context parameter value in the bean code. Next, we display the same value by using EL’s initParam variable. This variable contains, under specific parameter name keys, all the values of context parameters present in the application.

JSF get context param – bean code

package com.itcuties.examples.webapps;


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

public class ParamBean implements Serializable {

	private static final long serialVersionUID = 8541599579318786034L;

	 * This method returns the myParameter parameter value.
	 * @return
	public String getContextParameter() {
		return FacesContext

In the getContextParameter method we read myParameter context parameter value. To do that you need to gain access to the application’s ExternalContext. You can do that easy, by using this method invocation chain – FacesContext.getCurrentInstance().getExternalContext(). When you have the ExternalContext reference, then you can call getInitParameter method on it, which returns the value of the context parameter for the name that was provided to the call.

Download this sample code here.

This code is available on our GitHub repository as well.

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>