开发者

JSF - Another question on Lifecycle

开发者 https://www.devze.com 2023-01-28 20:18 出处:网络
Today I\'d like to know some features on the JSF Lifecycle. Let me start : 1 - Phase 2:Apply request Values - During this phase,each component in the view will search for its values in the request an

Today I'd like to know some features on the JSF Lifecycle. Let me start :

1 - Phase 2:Apply request Values - During this phase,each component in the view will search for its values in the request and set the new values to them

Uhm, ok nice. So, the View will be built due to the previous Beans parameters. After, there is a partial View, generated with the request values. (Right? Later, 开发者_StackOverflow社区in the 3° phase, they will be compared) . But, for example, if a values in the request list is absent during the creation of this last view? Values will be null?

2 - Phase 5: Invoke Application - Once all the values of the request has been successfully set to the backing bean the action events queued during the apply request values phase will be processed. In our case the submit buttons action method .

This is not clear at all. At this moment i have (on the beans) the values updated from the previous Phase (If the validation and the apply request aren't failed). Ok, so now what happens? What means the action events queued during the apply request values phase will be processed? It means that, for example, if the action is Submit the process is finished? That's why an ajax call, if not rendered in the 2° phase, will fail? Or where it fails?

3 - Phase 6: Render response - In this phase the component tree will be rendered to the client.

It means that the View on the server is updated by using the updated bean values? And, after this, the HTML code is created from this View? Or just it made the HTML code and save the View status?

Hope you can help me :)


Phase 2:Apply request Values - During this phase,each component in the view will search for its values in the request and set the new values to them

Uhm, ok nice. So, the View will be built due to the previous Beans parameters. After, there is a partial View, generated with the request values. (Right? Later, in the 3° phase, they will be compared) . But, for example, if a values in the request list is absent during the creation of this last view? Values will be null?

Basically the following is happening under the covers (here, input is UIInput and request is HttpServletRequest):

if (input.isRendered()) {
    String value = request.getParameter(input.getClientId());
    if (value != null) {
        input.setSubmittedValue(value);
    }
}

So, they will be untouched if there's no request parameter. They won't be set with null and just kept default.


Phase 5: Invoke Application - Once all the values of the request has been successfully set to the backing bean the action events queued during the apply request values phase will be processed. In our case the submit buttons action method .

This is not clear at all. At this moment i have (on the beans) the values updated from the previous Phase (If the validation and the apply request aren't failed). Ok, so now what happens? What means the action events queued during the apply request values phase will be processed? It means that, for example, if the action is Submit the process is finished? That's why an ajax call, if not rendered in the 2° phase, will fail? Or where it fails?

During 2nd phase basically the following will also happen (here, command is UICommand, request is HttpServletRequest and ActionEvent is ActionEvent):

if (command.isRendered()) {
    String value = request.getParameter(command.getClientId());
    if (value != null) {
        command.queueEvent(new ActionEvent(command)); // Queue for INVOKE_ACTION.
    }
}

Then, during invoke application phase, all events which are queued for the particular phase will be invoked.


Phase 6: Render response - In this phase the component tree will be rendered to the client.

It means that the View on the server is updated by using the updated bean values? And, after this, the HTML code is created from this View? Or just it made the HTML code and save the View status?

During this phase JSF walks through the component tree and all components will be encoded (will invoke the Renderer of all components, by default a HTML renderer). During encoding, the values will just be obtained from the model. The view itself won't be updated. Basically:

facesContext.getViewRoot().encodeAll();


1 - Phase 2:Apply request Values

This phase has nothing to do with the backing bean. Here, we just process the request parameters, and try to "link them" to a component in the view. During the Apply Request phase, these HTTP request parameters need to be converted and validated before they are injected into the actual bean.

2 - Phase 5: Invoke Application

In JSF, ActionEvents are handled by ActionListeners. When clicking the button, an ActionEvent is raised and queued to be processed at a later phase. A default Actionlistener is provided by JSF that picks up this ActionEvent and processes it in the Process Application Phase.

The Default ActionListener is implemented in such a way that it evaluates the EL expression, and uses the outcome to pass it on to a navigationlistener. So what you take for granted (pressing a button executes the EL expression in the action attribute and forwards to another page) is actually handled internally using an ActionListener.

3 - Phase 6: Render response -

A JSF view is an internal representation of the component tree and all value bindings. The actual HTML representation is handled by the ViewHandler.


Another excelent article about JSF lifecycle can be found at: http://palkonyves.blogspot.com.br/2013/08/demistifying-jsf-21-lifecycle-mojarra.html

0

精彩评论

暂无评论...
验证码 换一张
取 消