top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are JSF life cycle phases?

0 votes
309 views
What are JSF life cycle phases?
posted Sep 26, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

There are six lifecycle phases namely:
Restore view phase: Whenever a request arrives, this is the first phase that gets initiated. When the request arrives – that is, when a button or a link is clicked, jsf builds the view, prepares the event handlers, validates the ui components and saves the view in a faces context. This faces context will have all the previous request’s information to process the current request. If the request is an initial one, the JSF creates an empty view and displays it to the user during a postback. If the postback view already exists, the information is popped out from the saved state.
Apply request values: Once the components are restored from in the first phase, each component extracts its new value which might have been changed from the previous state through a decode method. The extracted value is then stored locally(native data type) along with the component. If the process of decoding fails, an error message is generated and stored in faces context for further action. If the components have their immediate JSF attributes set to true in the page then the events, validation and conversion related to the page will be processed. If any decode method calls the render response phase then the the control is redirected to render response phase itself.
If the application needs to redirect to a different application it can call FacesContext.responseComplete. By the end of this phase the new values will be set and messages, events will be queued.
Process validations phase: During this phase all the field related validations are processed and added to the component tree. Each and every rule is examined and compared with the values stored on the local component. If the values on the local component is invalid, error messages are registered in faces context and the same page is rendered again with the error message there by navigating to the render response phase.
Update model values phase: Since the Data validations are done in the validation phase now the corresponding server object properties are set and stored in the local components. The bean properties are updated to the corresponding input component attributes.
Invoke application phase: The events like submitting a form, click of a link are handled in this phase. If the processed views are reconstructed based on state information of previous request and if the event is fired it will be broadcasted to interested listeners. If redirection to different web application is invoked again the transition to response render phase takes place.
Render response phase: The Java Server Faces first checks whether it is a jsp page and if yes, the control is transferred to JSP Container. If the request is an initial one, the page is added to the component tree first and stored. If it is not an initial request, the component will already be stored and hence it just gets rendered. In either case the components will render themselves as the JSP container traverses the tags in the page. If any errors are encountered during this process the relevant messages are displayed. After the view is rendered the content will be stored so that when the same request arrives, it can be accessed and also be available for restore view phase.

answer Sep 27, 2017 by Sourav Kumar
...