Search code examples
jsfjsf-2faceletspage-lifecyclejavabeans

JSF - Another question on Lifecycle


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, 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 :)


Solution

  • 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();