Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

JSF%20Interview%20Questions%20and%20Answers

Question: Discuss life cycle in JSF.
Answer: The life cycle of a JavaServer Faces page is similar to that of a JSP page: The client makes an HTTP request for the page, and the server responds with the page translated to HTML. However, because of the extra features that JavaServer Faces technology offers, the life cycle provides some additional services to process a page.

JSF application lifecycle consist of six phases which are as follows

  • Restore view phase

  • Apply request values phase; process events

  • Process validations phase; process events

  • Update model values phase; process events

  • Invoke application phase; process events

  • Render response phase

Restore View Phase:

When a request for a JavaServer Faces page is made, such as when a link or a button is clicked, the JavaServer Faces implementation begins the restore view phase.

Apply Request Values Phase:

After the component tree is restored, each component in the tree extracts its new value from the request parameters by using its decode method. The value is then stored locally on the component. If the conversion of the value fails, an error message associated with the component is generated and queued on FacesContext. This message will be displayed during the render response phase, along with any validation errors resulting from the process validations phase.

Process Validations Phase:

During this phase, the JavaServer Faces implementation processes all validators registered on the components in the tree. It examines the component attributes that specify the rules for the validation and compares these rules to the local value stored for the component.

Update Model Values Phase:

After the JavaServer Faces implementation determines that the data is valid, it can walk the component tree and set the corresponding server-side object properties to the components' local values. The JavaServer Faces implementation will update only the bean properties pointed at by an input component's value attribute. If the local data cannot be converted to the types specified by the bean properties, the life cycle advances directly to the render response phase so that the page is rerendered with errors displayed. This is similar to what happens with validation errors.

Invoke Application Phase:

During this phase, the JavaServer Faces implementation handles any application-level events, such as submitting a form or linking to another page.

Render Response Phase:

During this phase, the JavaServer Faces implementation delegates authority for rendering the page to the JSP container if the application is using JSP pages. If this is an initial request, the components represented on the page will be added to the component tree as the JSP container executes the page. If this is not an initial request, the components are already added to the tree so they needn't be added again. In either case, the components will render themselves as the JSP container traverses the tags in the page.

Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook