First page Back Continue Last page Graphics


Notes:

Formal Phases of the JSF Life Cycle (continued)

Process Validation: Conversion and validation logic is executed for each component. This means both built-in validation/data conversion and custom validation/conversion are added onto the components. If a validation error is reported, an exception is thrown. The life cycle halts and the response is rendered with validation error messages. At the end of this phase, new component values are set, any validation or conversion error messages and events are queued on FacesContext, and any value change events are delivered.

Update Model: The component’s validated local values are moved to the model and the local copies are discarded. If you are using a backing bean for a JSF page to manage your UI components, any managed bean properties that are value-bound to UI component using the value attribute are updated with the value of the component.

Invoke Application: Any action bindings for command components or events are

invoked. Navigation is handled here depending on the outcome of action method (if any).

Setting the immediate Attribute

You can use the immediate attribute to allow components on the page to be validated in the Apply Request Values phase of the life cycle as opposed to the Process Validations phase:

Using immediate on an input component means that that component’s value is validated before any input components that do not have the immediate attribute set to true. Therefore, if a validation error occurs on an immediate input component, the life cycle moves from the apply request values phase (where the immediate attribute is evaluated) to the render phase, and validation does not run on any “nonimmediate” input components. Additionally, if the new value of an immediate input component is different from the existing value, then a ValueChangeEvent is raised. However, instead of the event being processed during the Process Validations phase, the event is processed at the end of the Apply Request Values phase. Therefore, any ValueChangeListener associated with the immediate input component executes before any command component’s ActionListener (assuming the command component occurs later in the page). You learn about event listeners in the lesson titled “Responding to Application Events.”

For command components, if set to immediate and the component has an action that returns a value for navigation, the life cycle proceeds directly to the Render Response phase. The validation and model update phases are skipped. A Cancel button is an example of when this would be used.