Sie sind auf Seite 1von 34

Advanced ADF Data Binding and Life Cycle

Copyright 2008, Oracle. All rights reserved.

Objectives
After completing this lesson, you should be able to do the following: Describe how data binding and the JavaServer Faces (JSF) page life cycle interact Define listeners and custom controllers to augment the ADFm life cycle Explain how the Application Development Framework (ADF) life cycle works

6-2

Copyright 2008, Oracle. All rights reserved.

Agenda
JSF Life Cycle ADF Faces Life Cycle JSF and ADF Faces Life Cycle

6-3

Copyright 2008, Oracle. All rights reserved.

Defining the JSF Life Cycle


JSF life cycle: Is a series of stages through which an application request passes before a result is presented to the requestor Can be watched and intercepted in a PhaseListener class Is repeated many times within a user application session There are six life cycle stages: Update Model Values Restore View Invoke Application Apply Request Values Render Response Process Validations

6-4

Copyright 2008, Oracle. All rights reserved.

JSF Life Cycle


Each page request invokes the JSF request life cycle. The JSF life cycle handles:
Page value submission Component validation Navigation Component display Component state management


6-5

The JSF life cycle phases use a UI component tree to manage the display of the Faces components. (f:view is the root component of this UI tree.) The FacesServlet object manages the requestprocessing life cycle in JSF applications. FacesServlet creates an object called FacesContext.
Copyright 2008, Oracle. All rights reserved.

JSF Request Life Cycle: Restore View


A request comes in through the JSF servlet. The request is examined for the viewId to load; viewId is bound to a page. The viewId is used by the framework to look up the components of the page.
If it is the first time a page is requested, the framework creates the component tree for this page. If the page has been requested before, the component tree gets reassembled.

Restore View Apply Request Values Process Validations Update Model Values Invoke Application Render Response

The current viewId is saved in the viewRoot property of the FacesContext.


Copyright 2008, Oracle. All rights reserved.

6-6

JSF Request Life Cycle: Apply Request Values

Restore View Apply Request Values Process Validations Update Model Values Invoke Application Render Response

The JSF components are retrieved from the JSF context. Component values are updated with the values in the request parameter. If a components immediate property is set to true, conversion and validation occur within this step, and value change events fire.

6-7

Copyright 2008, Oracle. All rights reserved.

JSF Request Life Cycle: Process Validations


The request parameter values are converted to the expected data types. Validation is performed for each component value, where immediate is not set to true. Value change events fire.

Restore View Apply Request Values Process Validations Update Model Values Invoke Application Render Response

6-8

Copyright 2008, Oracle. All rights reserved.

JSF Request Life Cycle: Update Model Values

Restore View Apply Request Values Process Validations Update Model Values Invoke Application Render Response

Until this step, the request only updated the components, setting their submittedValue property.

Now, the model (managed beans or in the ADF case, the binding container) is updated with the validated values.

6-9

Copyright 2008, Oracle. All rights reserved.

JSF Request Life Cycle: Invoke Application

Restore View Apply Request Values Process Validations Update Model Values Invoke Application Render Response

The Invoke Application phase manages any forms that the page submits and executes any business logic. It also processes any action events that are fired and evaluates any navigation actions that need to execute.

6 - 10

Copyright 2008, Oracle. All rights reserved.

JSF Request Life Cycle: Render Response

Restore View Apply Request Values Process Validations Update Model Values Invoke Application Render Response

The Render Reponse phase prepares the view for display.

6 - 11

Copyright 2008, Oracle. All rights reserved.

Using the immediate Attribute


This attribute is available as a property on UI components. Components that have immediate set to true are evaluated in the Apply Request Values phase.
Use case: Enforce a component to be evaluated before others. The life cycle continues if no error is found. No updated model data is available. To access user-provided input, call getSubmittedValue().

The developer has the option to short-circuit the JSF life cycle:
A ValueChangeEvent runs before validation is performed. Use ValueChangeListener to call the Render Response phase. Update the model manually only if needed. Use case: Cancel button that should navigate to another page without submitting the data

6 - 12

Copyright 2008, Oracle. All rights reserved.

Agenda
JSF Life Cycle ADF Faces Life Cycle JSF and ADF Faces Life Cycle

6 - 13

Copyright 2008, Oracle. All rights reserved.

ADF Faces Life Cycle Extension


Adds client-side life cycle: The ADF Faces framework provides client-side conversion and validation that does not require a server round trip.

Use custom JavaScript-based converters and validators that run on the page without a server round trip. Client-side validation triggers validation of the appropriate form or subform when a specific client event is queued.

6 - 14

Copyright 2008, Oracle. All rights reserved.

ADF Faces Life Cycle Optimization


Partial Page Rendering (PPR) optimizes the JSF life cycle: It sets clear boundaries on the component to be processed. Components such as tables use PPR to lazily fetch data: Life cycle jumps from the request phase to the render phase Handles additional data requests, such as when a user scrolls the table Cross-component refresh enables you to synchronize UI element instances with model changes.

6 - 15

Copyright 2008, Oracle. All rights reserved.

Agenda
JSF Life Cycle ADF Faces Life Cycle JSF and ADF Faces Life Cycle

6 - 16

Copyright 2008, Oracle. All rights reserved.

ADF Life Cycle


The ADF life cycle: Hooks into the JSF life cycle: A developer can use the JSF phases (available in the ADF life cycle) to interact with the request processing. Handles:
Data model preparation and update Data validation in the model layer Method execution on the business layer

Uses the binding container to make data available during the current page request

6 - 17

Copyright 2008, Oracle. All rights reserved.

The Big Picture


JSF Lifecycle Phases
Restore View

ADF Lifecycle Phases


JSF Restore View Init Context Prepare Model New Context For Same View Init Context Prepare Model

Apply Request Values Process Validation

JSF Apply Request Values JSF Process Validation JSF Update Model Values

Prepare Render

Update Model Values Validate Model Updates Invoke Application JSF Invoke Applications

For Same View Render Response

Prepare Render Meta Data Commit

Changed View?

yes

no

Render Response

6 - 18

Copyright 2008, Oracle. All rights reserved.

ADF Life Cycle in Action: Step 1


Restore View:
The URL for the requested page is passed to bindingContext. The page definition file that matches the URL is looked up. This phase provides the before and after phase events. You can create a listener and register it with the before or after event of this phase. The Initialize Context phase of the ADF Model layer life cycle listens for the after (JSF Restore View) event and then executes. The page definition file is read to create the bindingContainer object. The LifecycleContext class that is used to persist information throughout the ADF life cycle phases is instantiated and initialized with values for the associated request, binding container, and life cycle.
Copyright 2008, Oracle. All rights reserved.

JSF Restore View:


Initialize Context:

6 - 19

ADF Life Cycle in Action: Step 2


Prepare Model:
Binding container page parameters are prepared and evaluated. Taskflow parameters are passed into the flow. Any executables that have their refresh attribute set to prepareModel are refreshed based on the order of entry in the page definitions <executables> section. If the page was created using a template, and the template contains bindings that use the ADF Model layer, the templates page definition file is used to create the binding container for the template. If any task flow executable bindings exist (for example, if the page contains a region), the task flow binding creates an ADF Controller ViewPortContext object for the task flow, and any nested binding containers for pages in the flow are executed.
Copyright 2008, Oracle. All rights reserved.

6 - 20

ADF Life Cycle in Action: Step 3


Apply Request Values:
Each component in the tree extracts new values from the request parameters.

JSF Apply Request Values:


This phase provides the before and after phase events.

Process Validations:
Local values of components are converted and validated on the client. If there are errors, the life cycle jumps to the Render Response phase. Exceptions are also caught by the binding container and cached.

JSF Process Validations: This phase provides the before and the after phase events.
Copyright 2008, Oracle. All rights reserved.

6 - 21

ADF Life Cycle in Action: Step 4


Update Model Values:
The components validated local values are moved to the model and the local copies are discarded. For updateable components (such as an inputText component), corresponding iterators are refreshed if the refresh condition is set to the default (deferred) and the refresh condition (if any) evaluates to true.

JSF Update Model Values: This phase provides the before and the after phase events. Validate Model Updates:
The updated model is now validated against any validation routines set on the model. Exceptions are caught by the binding container and cached.

6 - 22

Copyright 2008, Oracle. All rights reserved.

ADF Life Cycle in Action: Step 5


Invoke Application: Action bindings for command components or events are invoked. JSF Invoke Application: This phase provides the before and the after phase events. MetaData Commit:
The changes to run-time metadata are committed. This phase stores any run-time changes made to the application by using the Metadata Service (MDS).

Initialize Context:
Initialize the context if navigation occurs. Initialize the page definition file for the next page.

Render Response: This phase prepares the returning values to be displayed. JSF Render Response: This phase provides the before and the after phase events.
Copyright 2008, Oracle. All rights reserved.

6 - 23

Task Flows
Are an extension to the JSF standard page flow engine Address some key enterprise requirements:
Page reuse Executing code in a flow (task flow, not page flow) Security Flow control Exception and transaction management

Are defined using a page flow diagram (similar to JSF but with more components) Also allow the definition of managed beans (similar to facesconfig.xml)

6 - 24

Copyright 2008, Oracle. All rights reserved.

Task Flow Components


Method Call
It invokes application logic within application control flows, not within the page markup itself as in standard JSF applications. It typically invokes a method on a managed bean.

Router
It evaluates an Expression Language (EL) expression and returns an outcome based on the value of the expression.

Save Point Restore


It restores a previous persistent Save Point in an application supporting save for later functionality.

Task Flow Call


It calls an ADF-bounded task flow from a particular point in an application.

Task Flow Return


It identifies when a bounded task flow completes and sends control flow back to the caller.

6 - 25

Copyright 2008, Oracle. All rights reserved.

More Task Flow Components


URL View
Redirects the root view port (for example, a browser page) to any URL addressable resource, even from within the context of an ADF region

View
Displays a JSF page or page fragment. Multiple View activities can represent the same page or same page fragment.

Control Flow Case


Identifies how control passes from one activity to the next in the application

Wildcard Control Flow Rule


Represents a control flow rule that can originate from any activities, the IDs of which match a wildcard expression Uses a trailing wildcard such as foo*

6 - 26

Copyright 2008, Oracle. All rights reserved.

Object Scope Life Cycle


Application scope: The object is available for the duration of the application. Session scope: The object is available for the duration of the session. PageFlow scope: The object is available for the duration of a bounded task flow. Request scope: The object is available for the duration between an HTTP request and a response sent back to the client.

6 - 27

Copyright 2008, Oracle. All rights reserved.

More on Object Scope Life Cycles


BackingBean scope:
It is used for only managed beans for page fragments and declarative components. The object is available for the duration between an HTTP request until a response is sent back to the client. Any managed bean for a page fragment or declarative component must use the BackingBean scope.

View scope: The object is available until the view port ID for the current view activity changes.

6 - 28

Copyright 2008, Oracle. All rights reserved.

Available Object Scopes

Page A

Page B

Page C

Page D

Page E

Request

ViewScope
PageFlow

Backing Bean
Session

Application

6 - 29

Copyright 2008, Oracle. All rights reserved.

About Regions

Page Region A region is a UI p1.jsff p2.jsff component whose p3.jsff content is based on a task flow definition. When first rendered, the regions content is that of the default view activity in the task flow. Any view activity used in the region must be created using page fragments, not pages. A page fragment is:

A JSF JSP document that can be rendered as content of another JSF page Similar to a page, except that it cannot contain elements such as <f:view>

6 - 30

Copyright 2008, Oracle. All rights reserved.

Task Flow and ADF Life Cycle


Regions are refreshed when the parent page is displayed. Bindings are refreshed based on property values. Even components that are not initially displayed are initialized. EL expression values of the RefreshCondition attribute are evaluated during the Prepare Render phase of the life cycle.
default: The region is refreshed only once. ifNeeded: Refreshes the region only if there has been a change to task flow binding parameter values

If the variable bindings is used within the EL expression, the context refers to the binding container of the parent page.
Copyright 2008, Oracle. All rights reserved.

6 - 31

Declarative Control Over Individual Page Life Cycle


Executables:
Iterator bindings invokeAction

Refresh attribute values:


ifNeeded: Fires both during the Prepare Model and Prepare Render phases prepareModel: Fires only during the Prepare Model phase renderModel: Fires only during the Prepare Render phase

RefreshCondition expression: Boolean expression, which controls whether the executable should fire at all

6 - 32

Copyright 2008, Oracle. All rights reserved.

Summary
In this lesson, you should have learned how to: Describe how data binding and JSF Page life cycle interact Define listeners and custom controllers to augment the ADFm lifecycle Explain how the ADF life cycle works

6 - 33

Copyright 2008, Oracle. All rights reserved.

Practice 6 Overview: Data Binding in Action


The practice has the following sections: Adding data-bound components to the CustomerOrders page Testing the page to ensure that previously defined functionality works

6 - 34

Copyright 2008, Oracle. All rights reserved.

Das könnte Ihnen auch gefallen