"JSF "


1 )   What is JSF ?

JavaServer Faces (JSF) is a Java-based Web application framework intended to
simplify development integration of web-based user interfaces.
JSF is a request-driven MVC web framework for constructing user interfaces using
components. As a display technology, JSF 2 uses Facelets. JSF 1.x uses JavaServer
Pages (JSP) for its displaytechnology.
One of the very imporant features of JSF is it's "A server-side event model"
A server-side event model : For dispatching events and attaching listeners to
core system functionality, such as "Before Render Response" or "After Validation"

2 )   What are the LifeCycle Phases of JSF page ?


  • LifeCycle Phases of JSF page
    Sample Img 2
The six phases of the JSF application lifecycle are as follows (note the event processing
at each phase):
1.Restore view
2.Apply request values; process events
3.Process validations; process events
4.Update model values; process events
5.Invoke application; process events
6.Render response

Phase 1: Restore view
In the first phase of the JSF lifecycle -- restore view -- a request comes through the FacesServlet
controller. The controller examines the request and extracts the view ID, which is determined by the name of the JSP page.
Phase 2: Apply request values
The purpose of the apply request values phase is for each component to retrieve its current
state. The components must first be retrieved or created from the FacesContext object,
followed by their values. Component values are typically retrieved from the request parameters,
 although they can also be retrieved from cookies or headers.

Phase 3: Process validation
The first event handling of the lifecycle takes place after the apply request values phase.
At this stage, each component will have its values validated against the application's
validation rules. The validation rules can be pre-defined (shipped with JSF) or defined by the developer

Phase 4: Update model values
The fourth phase of the JSF application lifecycle -- update model values -- updates the actual
values of the server-side model -- namely, by updating the properties of your backing beans
(also known as managed beans).

Phase 5: Invoke application
At the fifth phase of the lifecycle -- invoke application -- the JSF controller invokes the
application to handle Form submissions.
Phase 6: Render response
In the sixth phase of the lifecycle -- render response -- you display the view with all
of its components in their current state.

3 )   JSF Tags for html components ?

Tag Libs to be included :
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
HTML form:
... other JavaServer Faces tags and other content...
Hyper Link:
<h:commandLink id="check"
  rendered="#{cart.numberOfItems > 0}">
Table :
<h:dataTable id="items"
    <f:facet name="header">
      <h:outputText value="#{bundle.ItemQuantity}"/>
      <f:validateLongRange minimum="1"/>

4 )   Sample "faces-config.xml" ?


"faces-config" is going to have two high level Elements "navigation-rule" and  "managed-bean"

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"


5 )   Sample Event Handling in JSF ?

Event Handling :
<h:selectOneRadio id="category"
    <f:selectItems value="#{CDManagerBean.categories}"/>
Event Handling Method :
public void categorySelected(ValueChangeEvent event) {
    String value = (String) event.getNewValue();
    if (value != null) {
        this.subCategories = this.getSubcategoriesList(value);
    FacesContext context = FacesContext.getCurrentInstance();
Managed Bean :
  <description>The "backing file"
    bean that backs up the CD application</description>

6 )   How to add "FacesServlet" to Web.xml for a JSF application ?

Make for JSF has different "url-pattern" other than JSP.
<!-- JSF -->

    <servlet-name>Faces Servlet</servlet-name>