开发者

JSF - Question about Lifecycle

开发者 https://www.devze.com 2023-01-27 09:37 出处:网络
I was reading an article today about Lifecycle on JSF. I have some trouble to understand these points :

I was reading an article today about Lifecycle on JSF.

I have some trouble to understand these points :

1 - Phase 3 :Process validations - This is the phase in which the component may validate their new values. If the new value is valid and differs form the previous value a value-change event will be created and put in a queue. So in our example if the user change the name before submitting the form, a ValueChangeEvent object will be created by the UIInput component Object corresponding to the Name textbox and queued it for processing at the end of this phase.This is how the valueChangeInput method in the backing bean get invoked.

How can JSF know the difference between old value and the new one? The instances of the View Object are 2? The previous (the one before the request) and the new? (which have the values on the FacesContext added by the last process, Apply request Values)

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 .

So it send directly the instance of FacesContext to the last phase (Rend开发者_高级运维er response) that convert UI elements (and their values) to Html. So, when is that the getter methods (of the bean) are called?

Cheers


How can JSF know the difference between old value and the new one? The instances of the View Object are 2? The previous (the one before the request) and the new? (which have the values on the FacesContext added by the last process, Apply request Values)

The old value is the current model value. The new value is the submitted value. With following example,

<h:inputText value="#{bean.value}" />

JSF will basically do the following (conversion/validation omitted for brevity):

Object oldValue = bean.getValue();
Object newValue = request.getParameter(clientId);
if (oldValue == null ? newValue != null : !oldValue.equals(newValue)) {
    // Create and queue ValueChangeEvent.
}

So it send directly the instance of FacesContext to the last phase (Render response) that convert UI elements (and their values) to Html.

Not exactly that way, but yes, the render response will kick in when the invoke action is finished.


So, when is that the getter methods (of the bean) are called?

Yes, that happens during render response only when they are bound in the view.

You can find here another article which explains the JSF lifecycle in a more practical manner.

0

精彩评论

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