What is Java Server Faces (JSF) and jsf life cycle
JSF provides ease-of-use in the following ways:
- Provides reusable UI components to construct User interfaces.
- Provides facility in application data migration to and from the UI
- Provides facility to manage UI state across server requests
- Provides facility to wire client side events to server side application code
- Provides provision for building and reusable of custom UI components
- Provides encapsulation of the differences in markup across different browsers and client.
- Provides support for form processing
- Provides page-to-page navigation handling in response to UI events and model interactions.
Generally Web user interfaces follow a request / response pattern with
web servers to display required information on web interfaces. In the
case of Web browsers, an initial HTTP GET or HTTP POST request is made
to the Web server which responds with a required processed document /
data. The web server responses to each of these subsequent requests are
usually documents, images, JavaScript files, CSS Style Sheets and other
artifacts.
Here we will discuss JSF Faces View Request / Response life cycle. When JSF lifecycle involves in rendering the initial response, processing of initial request, a response for request and any automatically subsequent requests from user interface and their related responses is called a Faces View Request / Response.
Below diagram is of JSF Faces View Request / Response.
Below diagram is of JSF Faces View Request / Response.
There are well defined request processing life cycle phases, each Faces View Request/Response goes through these phases. There are three different scenarios for request / response
- Non faces request generates faces response
- Faces request generates faces response
- Faces request generates non faces response
Faces Response:
Faces response is the response which generates by the execution of the Render Response phase of the request processing life cycle.
Non-Faces Response:
None faces response is the response which generates by the execution of the render response phase of the request processing life cycle.
Faces Request:
It is the request that was sent from a previously generated Faces response.
It is the request that was sent from a previously generated Faces response.
Non-Faces Request:
A request that was sent to an application component like a servlet or JSP page, instead of a Faces view.
Web application may also receive non-Faces requests that generate non-Faces responses. Because such requests do not involve Java Server Faces at all.
Sample JSF Web Page Code:
Below is the example JSF Page code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Example Code</title>
</h:head>
<h:body>
<h3>JSF 2.0 Hello World Example - welcome.xhtml</h3>
<h4>Welcome #{sayHelloBean.name}</h4>
<h:form id="mainForm">
<h:outputLabel for="enterName" value="Enter Name"/>
<h:inputText id="enterName" value="#{sayHelloBean.name}"/>
<h:commandButton value="Say Hello" action="#{sayHelloBean.sayHello}"/>
</h:form>
</h:body>
</html>


0 comments
Post a Comment