JSF Life Cycle

JSF Life Cycle


Posted in : Java Posted on : May 25, 2012 at 1:07 PM Comments : [ 0 ]

In this tutorial you will learn about Life Cycle of JSF with diagram.

JSF Life Cycle

In this tutorial you will learn about Life Cycle of JSF with diagram.

Life Cycle of JSF is separated into various phases with the objective of encouraging sophisticated UI component model. Various tasks such as in view components validation of input data, conversion of input data to a server side specific data type etc. are performed by the JSF. Defined phases of JSF lifecycle generates the response for a request. Following figure explains the series of steps (lifecycle of JSF) for generating response for a given request.

JSF consists the 6 steps in its lifecycle which an application follows if a request has made for processing. These steps are defined as follows :

  • Restore View Phase
    When a request is made for a JSF page via the FacesServlet controller i.e when a link or button is clicked, implementation of JSF starts the Restore View Phase. In this phase JSF implementations creates the page view with wiring handlers and validators to component, and stored them in FacesContext instance, which is capable in processing a single request. This instance keeps all the required data to process this request and it can be accessed by all the application's component tags, event handlers, converters, and validators. When a request for a page is made first time an implementation of JSF makes the empty view and the life cycle moves forward to the render response phase meanwhile the tags in the page refers the components that populates this empty view but, if the view is already existed i.e in postback request view implementation of JSF restores the view with the help of the state information this information may stored on the client or the server.
  • Apply Request Values Phase
    After restoration of components in this phase each component retrieves the new value from the request parameters and is kept locally on the component. In this process as the feature of JSF data conversion is processed, in case data conversion can not be completed then the corresponding error message will be generated first and queued on FacesContext for showing this message on the render response phase. In case of the immediate attributes of the components on the page is set to true then the validation, conversion and events related to these components will be done in this phase. In case of application is redirected to the another web application or the application generated a response doesn't have any JSF components can use FacesContext.responseComplete. At last values of components are fixed to their new values and the event and messages are queued during this phase.
  • Process Validations Phase
    In this phase all the validations that are registered on the components are processed by the JSF implementation. In this process it tests whether the value for the component stored locally satisfies the component attributes specific rules for validation or not. If any error becomes related to the invalid local value the concerned message is added to the FacesContext instance and the life cycle moves forward to the render response phase and displays the error message as well as if there were conversion error at the Apply Request Values Phase. In case of any validate method or event listener called the renderResponse on the current FacesContext then JSF implementation will skip to render response phase. In case of the application is redirected to the another web application or the application generated a response doesn't have any JSF components can use FacesContext.responseComplete.
  • Update Model Values Phase
    In this phase if the data is valid the components local value is fix by the corresponding server-side object properties. The server-side model value is updated with actual values only when the bean properties bound to the input component's value attribute. As similar in the validation error if the data type of the local value is not matched to the specified bean properties the life cycle moves forward to the render response phase to display the page with error message. In case of the application is redirected to the another web application or the application generated a response doesn't have any JSF components can use FacesContext.responseComplete.
  • Invoke Application Phase
    In this phase application-level events like form submission, linking to another page are handled. Before entering to this phase JSF implementation converted, validated and applied the component values to the bean objects. In case of the application is redirected to the another web application or the application generated a response doesn't have any JSF components can use FacesContext.responseComplete. And in case the view that was in processing and reconstructed after a previous request by the state information and the event is evoked by the component can broadcast to interested listener.
  • Render Response Phase
    A final phase of the JSF lifecycle where a page is assigned for rendering into its container such if JSP page then JSP container. In case of the made request is an initial request components on this page will be added to the component tree but, if the request is except than the initial request then the components are already added to the component tree. In case of the postback request and the errors that are occurred in above of the phases are queued and a page contains the message or message tags are displayed on this page. In this phase the view is rendered and its state information i.e response state is stored for the later request response and this information is provided to the Restore View Phase.
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics