• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

Life Cycle of JSF Components

August 12, 2008 //  by Krishna Srinivasan//  Leave a Comment

Restore View

The JSF servlet builds the view of the requested page as a component tree that contains the information associated with all components. It also saves the view in a FacesContext instance, thereby making it possible to repopulate the page if necessary—for example, when the user doesn’t fill out a form as required. If the same page was displayed before and component states were saved, that information would also be taken into account. In this phase, JSF wires event handlers and validators (if any) to the components.

also read:

  • Introduction to JSF
  • JSF Interview Questions
  • Request Processing Lifecycle phases in JSF

Apply Request Values

The JSF servlet goes through the component tree and executes each component’s decode method, which extracts values from the request parameters and stores them locally in the component. It also automatically converts the parameters that are associated with object properties of non-string types. Conversion errors cause error messages to be queued to the FacesContext object. In some cases, typically when the user clicks on controls, the servlet also generates request events and queues them to FacesContext.

Process Request Events

The servlet calls the processEvent method for each component with one or more queued events. Each component decides to handle the events or delegate their handling to event handlers. In any case, the servlet proceeds with the next phase if all executed processEvent methods return false. Otherwise, it jumps directly to the Render Response phase.

Process Validation

The servlet invokes the validate methods of the validators that had been registered during the Restore View phase. For each validate method that returns false, the servlet queues an error message to the FacesContext.

Process Events

If validation or conversion errors are generated during the Process Validation phase, control jumps directly to the Render Response phase.

Update Model Values

Each UI component can be linked to a field in a Java object called the model object. During this phase, the values of the linked components are copied to the corresponding fields of the model object by executing the component method updateModel, which also does type conversions when necessary. Conversion errors cause error messages to be queued to FacesContext.

Process Events

If it turns out that conversion errors were generated during phase 6,control jumps directly to the Render Response phase.

Invoke Application

During this phase, the servlet processes the application-level events by executing the corresponding handlers. When the user submits a form or clicks on a link of a JSF application, the JSF servlet generates a corresponding application-level event. One of the tasks you have to do when developing a JSF application is to assign a handler (e.g., a JSP page) to each one of the possible application events.

Render Response

The servlet creates a response component tree and delegates the rendering of the page to Tomcat. Each component renders itself as Tomcat goes through the corresponding JSF tags. At the end of this phase, the state of the response is saved so that the servlet can access it during the Restore View phase of subsequent requests to the same page.

Category: JSFTag: LifeCycle

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Hiding and Overriding Methods In Java
Next Post: Struts 1.0 Vs Struts 2.0 »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact