Google News
logo
JSF - Interview Questions
Explain Java Server Faces life cycle.
The life cycle contains 6 phases :
 
1) Restore view : The life cycle begins with the restore view phase. When a link or button is clicked on the web page, a request is sent to JSF with operations as listed below:
 
 * View is built by JSF
 * Connects event handlers and validators to user interface components
 * Saves this View in FacesContext instance
 * Provides all information to FacesContext to process request

2) Apply request : Here, each component from the component tree is created. Use the decode method that captures and saves new values from request parameters. In case of any failure during conversion, it generates an error message and lists it on FacesContext. It will display validation messages or errors during the render response phase. JSF moves to render response phase when decode method event listeners call renderResponse method.
 
3) Process validation : During this phase, JSF processes component tree validators, examines attribute rules for validation, and compares them with the stored local value of the component. In case of invalid local value, JSF adds an error message to FacesContext instance, displaying the same page with an error message and with JSF life cycle moving further towards render response phase.
 
4) Model value update : After JSF verifies valid data, it sets the corresponding server-side object properties to the component’s local values and updates the bean properties, corresponding to the value attribute of the input component. When renderResponse from the current instance of FacesContext is being called by updateModels methods, JSF moves to the render response phase.
 
5) Invoke application : Application-level events like submitting form or forwarding to another page are being handled by Java Server Faces during this phase.
 
6) Render response : In case the application has JSP pages, JSF requests the application server to render the page, thereby adds components on the page to the component tree. Otherwise, an already built component tree need not add any components; JSP container move tags and renders components. The response state is saved after view content is rendered, making successive requests can access the state and its availability to restore view phase.
Advertisement