JavaServer Faces (JSF 2.0) Overview

What Is JavaServer Faces?

JavaServer Faces is a standard Java framework for building user interfaces for Web applications. It simplifies the development of the user interface, which is often one of the more difficult and tedious parts of Web application development.

JavaServer Faces is designed to simplify the developers task while development of user interfaces for Java Web applications in the following ways:

  • It Lets you create user interfaces from a set of standard, reusable server-side components.
  • It Provides a set of JSP tags to access those components.
  • It automatically manages the user interface state between multiple requests and multiple clients in a simplified manner.
  • It Provides a framework for implementing custom components

What Is JavaServer Faces?

JavaServer Faces is a standard Java framework for building user interfaces for Web applications. It simplifies the development of the user interface, which is often one of the more difficult and tedious parts of Web application development.

JavaServer Faces is designed to simplify the developers task while development of user interfaces for Java Web applications in the following ways:

  • It Lets you create user interfaces from a set of standard, reusable server-side components.
  • It Provides a set of JSP tags to access those components.
  • It automatically manages the user interface state between multiple requests and multiple clients in a simplified manner.
  • It Provides a framework for implementing custom components



JSF Features

JSF provides a set of standard features that makes it a powerful and standard among the existing technologies available for the development of web application based on java technologies. Some of the features have been given below.

  • JSF is standard web user interface framework for Java.
  • Built on top of Servlet API.
  • JSF is a component framework
  • UI components are stored on the server.
  • Easy to use third party components.
  • Event driven programming model.
  • Navigation handling.
  • i18N Support.

JSF Architecture

JSF was developed integrating MVC design pattern so that applications can be designed well with greater maintainability. To understand this fact we need to understand what is MVC design pattern, how MVC helps to design an application well and how can we make our web application easy to maintain.

A typical JSF application consists of the following parts:

  • JavaBeans components for managing application state and behaviour
  • Event-driven development
  • Pages that represent MVC-style views; pages reference view roots via the JSF component tree.

JSF MVC Implementation

In JSF's MVC implementation, backing beans mediate between the view and the model. Because of this, it's important to limit the business logic and persistence logic in the backing beans.One common alternative is to delegate business logic to a façade that acts as the model.

Unlike JSP technology, JSF's view implementation is a stateful component model. The JSF view is comprised of two pieces: the view root and JSP pages. …The view root is a collection of UI components that maintain the state of the UI. …The JSP page binds UI components to JSP pages and allow you to bind field components to properties of backing beans



The JavaServer Faces lifecycle

Life cycle of a JSF web application starts when user makes a request. On submission of a page various further tasks are performed like validation of data provided in components in the view, data conversion according to types specified on server side bla bla.

The JSF application lifecycle contains six phases:-

  1. Restore View

  2. Apply requests

  3. Process Validations

  4. Update model values

  5. Invoke applications

  6. Render response

jsf life cycle

Restore view

RestoreView is the first phase in the JSF lifecycle. This phase is used for constructing view to display in the front end. Every view has it's own view id and it is stored in the FacesContext's session object. JSF View is collection of components associated with its current state.

Apply Requests

After the component tree is restored, each component in the tree extracts its new value from the request parameters by using its decode method. The value is then stored locally on the component. If the conversion of the value fails, an error message associated with the component is generated and queued on FacesContext. This message will be displayed during the render response phase, along with any validation errors resulting from the process validations phase.

Process Validations

During this phase, the JavaServer Faces implementation processes all validators registered on the components in the tree. It examines the component attributes that specify the rules for the validation and compares these rules to the local value stored for the component.

Update model values

After the JSF checks that the data is valid, it walks over the component tree and set the corresponding server-side object properties to the components' local values. The JSF will update the bean properties corresponding to input component's value attribute.

If any updateModels methods called renderResponse on the current FacesContext instance, the JSF moves to the render response phase.

Process Validations

During this phase, the JavaServer Faces implementation processes all validators registered on the components in the tree. It examines the component attributes that specify the rules for the validation and compares these rules to the local value stored for the component.

Invoke application

During this phase, the JavaServer Faces implementation handles any application-level events, such as submitting a form or linking to another page. At this point, if the application needs to redirect to a different web application resource or generate a response that does not contain any JavaServer Faces components, it can call FacesContext.responseComplete. If the view being processed was reconstructed from state information from a previous request and if a component has fired an event, these events are broadcast to interested listeners.

Render response

During this phase, the JavaServer Faces implementation delegates authority for rendering the page to the JSP container if the application is using JSP pages. If this is an initial request, the components represented on the page will be added to the component tree as the JSP container executes the page. If this is not an initial request, the components are already added to the tree so they needn't be added again. In either case, the components will render themselves as the JSP container traverses the tags in the page.



comments powered by Disqus