Wednesday, December 8, 2010

JSF(Java Server Faces) : Introduction

JSF(Java Server Faces), initially implemented by Sun as a Framework and released as JSF version 1.0. Its next release was JSF version 1.1, however, its currently used release is JSF 1.2 under JEE 5.

JSF 1.2 is technology and is intended to develop web based applications quickly. JSF technology specification given by SUN Microsystem and implemented by two vendors :-

1. SUN RI(Reference Implementation)
2. Apache (My Faces)

Other vendor do exists in this arena as given below :-
* Rich Faces
* A4J (AJAX 4 JSF)
* Ice Faces

Like Struts framework, JSF is also implemented based on two popular design patters :-
* Front Controller
* MVC design pattern


----------------------------------------------------
Presentation | Controller | Model Layer
----------------------------------------------------
JSP I/P --> FacesServlet<-->JSF BEAN

web.xml (DD) Model
faces-config.xml
JSP O/P <--

----------------------------------------------------

FacesContext :
--------------
javax.faces.context
Class FacesContext

java.lang.Object extended by javax.faces.context.FacesContext

public abstract class FacesContext extends java.lang.Object


FacesContext contains all of the per-request state information related to the processing of a single JavaServer Faces request, and the rendering of the corresponding response. It is passed to, and potentially modified by, each phase of the request processing lifecycle.

A FacesContext instance is associated with a particular request at the beginning of request processing, by a call to the getFacesContext() method of the FacesContextFactory instance associated with the current web application. The instance remains active until its release() method is called, after which no further references to this instance are allowed. While a FacesContext instance is active, it must not be referenced from any thread other than the one upon which the servlet container executing this web application utilizes for the processing of this request.


FacesContext object is created by the Framework Servlet (i.e FacesServlet). Whenever a request arise, there will be only one FacesContext object. FacesContext object holds the following information with respect to request which is currently under processing :-

1. UIViewRoot (javax.faces.component.UIViewRoot)
2. Error Messages related to validations
3. Error Messages related to converstions
4. Response stream in terms of ByteStream
5. ExternalContext (public abstract class ExternalContext extends java.lang.Object)
6. RenderKit (public abstract class RenderKit extends java.lang.Object)