Understanding the Request Processing Lifecycle Phases

来源:互联网 发布:菜鸟网络 股东 编辑:程序博客网 时间:2024/06/05 11:26
The Lifecycle object processes a JSF request (encapsulated in the FacesContext object; the FacesContext is the object that is read and modified by Lifecycle during processing) in six phases, executed in the following order:

Reconstitute Component Tree 
A JSP page in a JSF application is represented by a component tree. This phase starts the Lifecycle request processing by constructing this tree. Each component tree has an identifier that is unique throughout the application. The identifier of a component tree is the path information portion of the request URI. For a request with the URI /faces/index.jsp, for instance, the tree identifier is /index.jsp. The constructed component tree is then saved in the FacesContext object for processing by the following request processing phases. 

Apply Request Values
In this phase, the local value of each component in the component tree is updated from the current request. A value can come from a request parameter, a header, a cookie, and so on. During this phase, a component may queue events. These events will be processed during the process event steps in the request processing lifecycle. 

Process Validations
After the local value of each component is updated, in the Process Validations phase, the Lifecycle object will validate those values if necessary. A component that requires validation must provide implementation of the validation logic. Alternatively, a JSF programmer can register zero or more validators with the component. If one or more external validators are found, the local value of each component will be validated using the validation logic in these external validators. 

Update Model Values 
This phase can be reached only if the local values of all components in the tree are valid. In this phase, the Lifecycle object updates the application’s model data. During this phase, a component may again queue events. 

Invoke Application 
During this phase, the JSF implementation handles any application level events, such as submitting a form or linking to another page. 

Render Response
In this phase, the JSF implementation renders the response to the client.
The Apply Request Values, Process Validations, Update Model Values, and Invoke Application phases in the request processing lifecycle may queue events in the FacesContext instance associated with the current request. Therefore, the JSF implementation must handle these events after these phases.
Between two phases, the Lifecycle object checks any event listener that needs to be called. When writing an event listener, you can choose after which phase the listener should be executed. Alternatively, you can write an event listener that is called after various phases.







原创粉丝点击