Introduction to the JSF Lifecycle and ADF Faces

Using the JSF Lifecycle with ADF Faces 4-3 value is entered, in which case no validation is run. For more information about conversion and validation, see Chapter 6, Validating and Converting Input. At the end of this phase, converted versions of the local values are set, any validation or conversion error messages and events are queued on the FacesContext object, and any value change events are delivered. ■ Update Model Values: The component’s validated local values are moved to the model, and the local copies are discarded. ■ Invoke Application: Application-level logic such as event handlers is executed. ■ Render Response: The components in the tree are rendered. State information is saved for subsequent requests and for the Restore View phase. To help illustrate the lifecycle, consider a page that has a simple input text component where a user can enter a date and then click a command button to submit the entered value. A valueChangeListener method is also registered on the component. Example 4–1 shows the code for the example. Example 4–1 Sample Code to Illustrate the JSF Lifecycle af:form af:inputText value={mybean.date} valueChangeListener={mybean.valueChangeListener} af:convertDateTime dateStyle=long af:inputText af:commandButton text=Save actionListener={mybean.actionListener} af:form Suppose a user enters the string June 25, 2005 and clicks the submit button. Figure 4–2 shows how the values pass through the lifecycle and where the different events are processed. Tip: In short, for an input component that can be edited, the steps for the Process Validations phase is as follows: 1. If a converter fails, the required check and validators are not run. 2. If the converter succeeds but the required check fails, the validators are not run. 3. If the converter and required check succeed, all validators are run. Even if one validator fails, the rest of the validators are run. This is because when the user fixes the error, you want to give them as much feedback as possible about what is wrong with the data entered. For example suppose you have a dateTimeRange validator that accepted dates only in the year 2010, and you had a dateRestrictionValidator validator that did not allow the user to pick Sundays. If the user entered July 5, 2009 a Sunday, you want to give the feedback that this fails both validators to maximize the chance the user will enter valid data. 4-4 Web User Interface Developers Guide for Oracle Application Development Framework Figure 4–2 Example of Values and Events in the JSF Lifecycle

4.2 Using the Immediate Attribute

You can use the immediate attribute to allow processing of components to move up to the Apply Request Values phase of the lifecycle. When actionSource components such as a commandButton are set to immediate, events are delivered in the Apply Request Values phase instead of in the Invoke Application phase. The actionListener handler then calls the Render Response phase, and the validation and model update phases are skipped. For example, you might want to configure a Cancel button to be immediate, and have the action return a string used to navigate back to the previous page for more information about navigation, see Chapter 18, Working with Navigation Components . Because the Cancel button is set to immediate, when the user clicks the Cancel button, all validation is skipped, any entered data is not updated to the model, and the user navigates as expected, as shown in Figure 4–3 . Using the JSF Lifecycle with ADF Faces 4-5 Figure 4–3 Lifecycle for Command Button Set to Immediate As with command components, for components that invoke disclosure events, such as a showDetail component, and for editableValueHolder components components that hold values that can change, such as an inputText component the events are delivered to the Apply Request Values phase. However, for editableValueHolder components, instead of skipping phases, conversion, validation, and delivery of valueChangeEvents events are done earlier in the lifecycle, during the Apply Request Values phase, instead of after the Process Validations phase. No lifecycle phases are skipped. Figure 4–4 shows the lifecycle for an input component whose immediate attribute is set to true. The input component takes a date entered as a string and stores it as a date object when the command button is clicked. Note: A command button that does not provide any navigation and is set to immediate will also go directly to the Render Response phase: the Validation, Update Model, and Invoke Application phases are skipped, so any new values will not be pushed to the server. 4-6 Web User Interface Developers Guide for Oracle Application Development Framework Figure 4–4 Immediate Attribute on an Input Component Setting immediate to true for an input component can be useful when one or more input components must be validated before other components. Then, if one of those components is found to have invalid data, validation is skipped for the other input components in the same page, thereby reducing the number of error messages shown for the page. Performance Tip: There are some cases where setting the immediate attribute to true can lead to better performance: ■ When you create a navigation train, and have a commandNavigationItem component in a navigationPane component, you should set the immediate attribute to true to avoid processing the data from the current page train stop while navigating to the next page. For more information, see Section 18.8.1, How to Create the Train Model. ■ If an input component value has to be validated before any other values, the immediate attribute should be set to true. Any errors will be detected earlier in the lifecycle and additional processing will be avoided.