A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Tuesday, September 28, 2010


8:26:00 PM Posted by Satish Kumar , , , , No comments

What is JSF

 JavaServer Faces (JSF) is a UI component based Java Web application framework. JSF is serverbased, e.g. the JSF UI components and their state are represented on the server with a defined life-cycle of the UI components. JSF is part of the Java EE standard.

A JSF application run in a standard web container, for example Tomcat or Jetty . 

A JSF application

A JSF application consists of web pages with JSF UI components. A JSF application requires also some configuration files ("faces-config.xml" and "web.xml").

The faces-config.xml defines:

  1. Managed Bean - the data elements of the JSF application (managed beans and backing beans) Represents a Java class which will be created dynamically during runtime of the JSF application. It can be defined for which scope the bean is valid (Session, Request, Application or none).
  2. the navigation between web pages
  3. data validators - Used to check the validity of UI input
  4. data converters -Used to translate between UI and model
Managed beans are simple Java objects (POJO's) which are declared in "faces-config.xml" and can be used in an JSF application. For example you can define a Java object "Person". Once you define the object in faces-config.xml you can use the attributes of Person in your JSF UI components, e.g. by binding the value "firstName" of this object to an JSF input field.

JSF uses the Unified Expression Language (EL) to bind UI components to object attributes or methods. 

Value and Method Binding

In JSF you can access the values of a managed bean via value binding. For value binding the universal Expression Language (EL) is used (to access bean and / or methods). In JSF you do not need to specify the get() or set() method but just the variable name.

Method binding can be used to bind a JSF component, e.g. a button to an method of a Java class.

  • Expression Language statements either start with "${" or with "#{" and end with "}". JSP EL expressions are using the ${...} syntax. These EL expressions are immediately evaluated. JSF EL expressions are of the type #{...}. These are only evaluated when needed (and otherwise stored as strings).

Prerequisites to use JSF  

To use JSF you need: 

  1. JSF Implementation (in the form of the JSF jars)
  2. The JSTL tags library
  3. A Java runtime environment
  4. A web-container to use JSF in (for example Tomcat)
JSF Main features

JSP has the following main features:

  1. JSP is based on the Model-View-Controller concept
  2. JSP has a stateful UI component model, e.g. each component is aware of its data
  3. JSF separates the functionality of a component from the display of the component. The renderer is responsible of displaying the component for a certain client. This renderer can get exchanged. The standard renderer for JSF components is the HTML renderer.
  4. JSP support listeners on UI components
  5. JSP support data validation, data binding and data conversion between the UI and the model
JSP and JSF 

In this tutorial the JSF application will be build based on JavaServer Pages (JSP's). JSTL tags are used to include JSF UI components into the JSP. This is standard in JSF 1.2. The JSF 2.0 version is using Facelets. 

JSF configuration files

JSF is based on the following configuration files:

  1. web.xml - General web application configuration file
  2. faces-config.xml - Contains the configuration of the JSF application.

JSF requires the central configuration list "web.xml" in the directory WEB-INF of the application. This is similar to other web-applications which are based on servlets.

You must specify in "web.xml" that a "FacesServlet" is responsible for handling JSF applications. "FacesServlet" is the central controller for the JSF application. "FacesServlet" receives all requests for the JSF application and initializes the JSF components before the JSP is displayed.


"faces-config.xml" allows to configure the application, managed beans, convertors, validators, and navigation.


Post a Comment