Application Life Cycle
The most critical part of JSF to understand is its application life cycle. The entire life cycle starts when
the web application running JSF receives a request, runs through six phases, and then renders a
response and displays it to the user. The six phases are listed here:
Restore view: In a JSF application, every view is associated with a view ID and is
1.
stored in the FacesContext's (under package javax.faces.context) session
object. In JSF, a view is a collection of components associated with its current
state, which can be stored in either the server or client side (controlled by the
parameter javax.faces.STATE_SAVING_METHOD) in a web deployment
descriptor. When a user takes an action in the view and sends a request to the
server, the first phase in JSF is to restore the view back from its state.
Apply requests: After the component tree is restored, each component in the
2.
tree extracts its new value from the request parameters by using its decode
method.
Process validations: In this phase, the JSF implementation processes all
3.
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. JSF 2 fully supports
validation with JSR-303 Bean Validation.
Update model values: Upon validation completion, the JSF implementation
4.
will walk through the component tree and set the corresponding server-side
object properties to the components' local values. Only the bean properties
pointed at by an input component's value attribute will be updated. In this
binding process, type conversion and formatting also occurs, and in case the
conversion failed, the life cycle advances directly to the render response phase
so that the page is rerendered with errors displayed.
Invoke application: In this phase, the JSF implementation invokes the
5.
application to handle form submissions. At this point, the component values
will have been converted, validated, and applied to the model objects, so they
can be used to execute the application's business logic. During the execution,
the JSF implementation will handle any application-level events, such as
submitting a form or linking to another page. In addition, if the view being
processed was reconstructed from state information from a previous request,
and if a component has fired an event, these events are broadcast to
interested listeners.
Render response: In this final phase, the resulting view is displayed with all of
6.
its components in their current state.
You can install your own phase listeners by creating a class that implements the
javax.faces.event.PhaseListener interface into the life cycle to do whatever you want before or after
each or every phase. A phase listener has full access to the entire JSF framework, including manipulating
the view.
Figure 18-6 shows the life cycle.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home