JavaServer Faces

from Wikipedia, the free encyclopedia
JavaServer Faces

Basic data

developer Eclipse Foundation
Current  version 2.3
(April 17, 2017)
operating system platform independent
programming language Java
category Framework
License Eclipse Public License 2.0, GPL linking exception

JavaServer Faces ( JSF for short ) is a framework standard for developing graphical user interfaces for web applications . Based on servlets and JSP technology, JSF is one of the web technologies of the Java Platform, Enterprise Edition (Java EE). With the help of JSF, the developer can easily integrate components for user interfaces in web pages and define the navigation . Requirements for developing JSF content are the JDK , a servlet container (e.g. Apache Tomcat ) and a basic understanding of HTTP and the Java programming language . An integrated development environment can be used to simplify development .


In order to reduce redundancies in the code and to improve the reusability of the UI code over several projects, components can be created and used. JSF components have a hierarchical structure. Similar to the Java Swing API, there are container components in JavaServer Faces that can contain components. In order to better structure the application, there is a strict separation between model , presentation and control , as provided by the model-view-controller concept.

A central concept of JavaServer Faces is the view . This is a tree structure made up of JSF components. Such a structure occurs exactly once per call, i.e. once per page when using JavaServer Pages (JSP). The view is set up at the beginning of the JSF life cycle, immediately after the request has been received from the client. In the last phase of the life cycle, the components of the views are called recursively, starting with the root, in order to generate the answer, for example an HTML page. The controller component, which controls user input, can be implemented in JavaServer Faces using its own components or with a so-called handler . These are mostly written with Java. The actual logic of the application takes place in the model . With JavaServer Faces, the model components are so-called Java beans (Java classes) that are managed by the container. JSF web applications usually have no HTML code worth mentioning. The HTML code is only visible in the source code of the generated page. JSF components have their own renderers . These renderers convert the pages written with JSF into HTML code so that any HTML web browser can display the page. Own renderers can be written for other output formats.

Life cycle

JavaServer Faces lifecycle diagram

The specification of the JavaServer Faces defines a so-called life cycle that a JSF application runs through with each call. This life cycle is divided into six phases .

  1. Restore View ( "view restore") selected on the basis of the incoming request a view (View) and builds the matching component tree on.
  2. Apply Request Values extracts parameters from the request (usually an HTTP post request) and assigns them to the appropriate JSF components, such as input fields.
  3. Process Validations checks the validity of the previously determined entries. Separate converter and validator objects that were assigned to the components in the view definition are used for this purpose.
  4. Update Model Values assigns the previously determined values ​​to the model objects.
  5. Invoke Application calls methods defined by the application, for example when a button has been pressed.
  6. Render Response ultimately generates the response to the original request, for example an HTML page. For this purpose, so-called renderers are called which are assigned to the view components.

If errors occur or if, for example, an HTML page that contains no JSF components is to be called as a response, individual phases can be skipped.


The JavaServer Faces specification is implemented by a number of frameworks. These are usually supplied in JEE containers and can often only be exchanged with difficulty. These include, for example:

Component frameworks

Component frameworks extend JSF implementations. They can be used to generate JavaScript and Ajax , for example .

Various companies also offer graphic development tools for JSF.


The JSF - Specification was under the Java Community Process developed (JSR 127) by a number of well-known companies and adopted in version 1.1 on May 27 of 2004. Version 1.2 (JSR 252) was published on May 11, 2006. The current version of the reference implementation Mojarra 1.2_15 was released on September 24, 2010.

Version 2.0 (JSR 314) brought Ajax support in particular . It has been available since December 2009 and can be downloaded from the Oracle homepage. An implementation as well as a tutorial and further documentation are available for viewing and downloading in the Mojarra Project ; the current version of the Mojarra reference implementation is 2.0.8. JSF 2.1 is a maintenance release of version 2.0, the specification was released on November 21, 2010, the current version of the Mojarra reference implementation is 2.1.6. The JSF 2.2 version was released on April 15, 2013. In particular, it contains the following innovations: Support for HTML5 such as the passing on of new HTML5 attributes or custom data attributes, extended flow support through its own context and dependency injection scope ( @FlowScoped) in addition to the already existing ConversationScope ( @ConversationScoped), stateless views by setting the attribute transient="true", as well as Resource Library Contracts, a first approach to provide resources for selectable appearance.

JavaServer Faces includes

The main difference to JSP -EL is not only due to the preceding # , but also in the language itself. The JavaServer Pages-Expression Language is more dynamic than the JavaServer Faces-Expression Language. The JavaServer Faces-EL is more stateful (more static), comparable to the Java Swing components. JSF's Expression Language has a bidirectional value binding, i. In other words , it can read (e.g. initialize) and write (e.g. bind values ​​to property) properties (properties of a bean). The following table shows the types of expression in the JSF Expression Language:

Expression Language Expression example
Values #{}- name is a property of the handler bean
Method binding #{handler.actionMethode}- actionMethode is a method of the handler bean
Arithmetic / Logical #{5+8}, #{65/5}, #{99>90}, #{!(5>6)||(8<4)}

When developing JavaServer Faces pages, you should avoid combining JSP and JSF expressions, as this can lead to problems.

Managed Bean Mechanism

The Managed Bean mechanism allows POJOs with a specific scope ( English scope ), and initial values for the so-called Managed Properties (in the special case that the bean type java.util.Listor java.util.Mapis) to be provided. This can be configured either in the XML configuration of the JSF application or from JSF 2.0 (min. Java version 1.5) as an additional option with annotations directly in the bean. Managed beans can be used directly (e.g. in facelets) with the help of EL expressions.

Scopes of Managed Beans (Engl. Scope )

The scope of a bean determines how long a bean has existed and under what circumstances it is considered to exist. As mentioned earlier, managed beans with managed properties can be injected into other managed beans. Note that the injected bean has a larger scope than the bean into which it is injected. The reason for this is that the injected bean is otherwise potentially more short-lived than the bean into which it is injected.

The following table shows all areas of validity in the current JSF version (2.1) sorted according to the size of the area of ​​validity with the most short-lived scope at the top.

Value XML <managed-bean-scope> Annotation Scope
request @RequestScoped valid as long as the current request is being handled
view @ViewScoped valid as long as the current view is valid
session @SessionScoped valid for one session
application @ApplicationScoped valid for the application
none @NoneScoped valid as the bean into which it was injected

JSF standard tags (not complete)

Tag name description
<f: view> Creates an instance of the javax.faces.component.UIViewRoot class. All contained components become child components of the view.
<h: form> Binds input components in a form. Sends POST requests via HTTP.
<h: panelGrid> In HTML <table> tag. The number of columns determines the columns attribute
<f: facet> Defines a facet as a child element of a container (e.g. heading for a table)
<h: outputText> Normal HTML text
<h: outputLabel> In HTML <label> tag. Identification of an input field
<h: panelGroup> Container that combines several JSF tags into one tag
<h: inputText> In HTML <input> tag with type = "text", value attribute refers to the components (e.g. EL expression)
<h: inputSecret> In HTML <input> tag with type = "password"
<h: commandButton> Button in HTML. <input> tag with type attribute (submit, reset, image). By default: submit. Submits form and triggers ActionEvent (via bean method).
<h: message> Outputs the first error message for the components specified in the for attribute. ErrorStyle attribute can be used as a CSS error display.


Web links

Commons : JavaServer Faces  - collection of images, videos and audio files

Individual evidence

  1. .
  2. a b Mojarra JavaServer Faces homepage. Retrieved February 19, 2017 .
  5. RichFaces, accessed January 18, 2011
  6. Oracle Mojarra JavaServer Faces Download, accessed January 18, 2011
  7. a b Oracle Mojarra JavaServer Faces. Retrieved January 19, 2012 .
  8. ^ Andy Bosch: What's new in JSF 2.1. Retrieved October 9, 2011 .
  9. JSR # 344 JavaServerTM Faces 2.2 Final Approval Ballot
  10. What's new in JSF 2.2?