Vous êtes sur la page 1sur 40

Implementing Data Binding Concepts

Copyright 2008, Oracle. All rights reserved.

Objectives
After completing this lesson, you should be able to do the following: Describe the scope and role of the binding files Define Application Development Framework (ADF) Model binding types Define ADF Model executables and how to use them Manage data-bound components with the page definition file Bind data by using Expression Language (EL)

5-2

Copyright 2008, Oracle. All rights reserved.

Agenda
Defining ADF Model binding Describing the scope and role of the binding files Managing data-bound components with the page definition file Data control and Business Components (BC)

5-3

Copyright 2008, Oracle. All rights reserved.

What Is Data Binding?


It is a declarative data binding facility. It implements the JSR-227 specification.
Implemented as the data control for:

Any business service Any UI

5-4

Copyright 2008, Oracle. All rights reserved.

The Heart of ADF: ADFm


Desktop ADF Swing Office JSP Browser-based JSF ADF Faces
View

Struts

JSF/ADF Controller

Controller

ADF Model (JSR-227)


Java EJB BAM BPEL ADF BC Web Services BI XML Portlet

Model

Toplink

Business Services

Data Services
Relational Data XML Data

Legacy Data

Packaged Apps

5-5

Copyright 2008, Oracle. All rights reserved.

ADF Model Data Control Concepts


Abstracts the implementation of Business Services Uses standard metadata interface to describe the services operations and data collection At design time, simplifies binding components to the data control operation or the data collection At run time, wires business service data controls to UI bindings from XML files Has the following benefits:
You write less code. You work the same way with any UI and Business Service technology. You gain useful run-time features because you do not have to code them yourself.
5-6

Copyright 2008, Oracle. All rights reserved.

Application Module in the Data Control Palette


ADF BC data controls are exposed through an application module. Data controls are usable with the drag-and-drop functionality.

5-7

Copyright 2008, Oracle. All rights reserved.

Nested Application Modules

5-8

Copyright 2008, Oracle. All rights reserved.

Changing the Application Module Data Control Name


You can change the default application module name of the data control.

5-9

Copyright 2008, Oracle. All rights reserved.

ADF Data Bindings Concepts


Data bindings abstract the details of how to access data from data collections and how to invoke its operations. There are three kinds of data binding objects:
Iterator bindings to bind to an iterator that tracks the current row in a data collection (Results returned to the page) Value bindings to connect the UI components to the attributes in a data collection (Text values entered on the page) Action bindings to invoke custom or built-in operations on a data control or its data collections (The Create button)

5 - 10

Copyright 2008, Oracle. All rights reserved.

ADFm: Data Controls and Data Bindings


User interface

Data bindings

Data controls

Business Services

5 - 11

Copyright 2008, Oracle. All rights reserved.

ADF Model Overview


A binding exposes a property or table from the underlying model in a generic EL-accessible way.

Text binding

<af:inputText value= #{bindings.Ename.inputValue}> <af:commandButton action=#{bindings.Commit}> <af:selectItems items= #{bindings.Deptno.items}> <af:table value= #{bindings.DeptView. collectionModel}>

Action binding Data control ADFm bindings List binding

Table binding

5 - 12

Copyright 2008, Oracle. All rights reserved.

ADF Model Bindings


Each page has its own set of bindings. All the bindings for a given page are defined in a PageDef.xml file. PageDefinition is also called BindingContainer. The mapping from viewId to pageDef is Text binding in the DataBindings.cpx file.
Action binding

viewId browse.jspx

BindingContext DataBindings.cpx

PageDefinition browsePageDef.xml

List binding

Table binding

#{bindings.DeptView}
5 - 13

Copyright 2008, Oracle. All rights reserved.

Agenda
Defining ADF Model binding Describing the scope and role of the binding files Managing data-bound components with the page definition file Data control and Business Components (BC)

5 - 14

Copyright 2008, Oracle. All rights reserved.

DataBindings.cpx File
Provides the metadata from which the Oracle ADF binding objects are created at run time Uses XML syntax Specifies:
<pageMap> <dataControlUsages> <pageDefinitionUsages>

5 - 15

Copyright 2008, Oracle. All rights reserved.

DataBindings.cpx File: Details


Locates the correct PageDef for a page Defines the data control usage of the project

5 - 16

Copyright 2008, Oracle. All rights reserved.

DataBindings.cpx Properties: Synchronization Mode


Use Immediate mode for performance (now the default). Batch mode is best reserved for n-tier.

5 - 17

Copyright 2008, Oracle. All rights reserved.

Agenda
Defining ADF Model binding Describing the scope and role of the binding files Managing data-bound components with the page definition file Data control and Business Components (BC)

5 - 18

Copyright 2008, Oracle. All rights reserved.

PageDef.xml File
The key data binding artifact: Is accessible through the visual editors context menu or the link on its Bindings tab Describes the service usage of a particular page, panel, or region XML file content: Default location controlled by the ADFm Settings > PageDef subpackage project property Run-time location determined by the DataBindings.cpx file (see <context-param> CpxFileName in web.xml) Three sections (in order of interest, and not appearance): 1. Bindings 2. Executables 3. Parameters
5 - 19

Copyright 2008, Oracle. All rights reserved.

Examining a Page Definition File


The file displays in:
The Structure pane The editor

Three sections are displayed, with detailed bindings in each.

5 - 20

Copyright 2008, Oracle. All rights reserved.

Bindings Sections
The data is accessed via the bindings object on the HTTP request, conventionally via EL: #{bindings.ProdId}
#{bindings} provides access to everything that is defined in the Binding Container or page definition. Individual bindings (such as Table Bindings):

Are objects Have attributes other than value Are accessible using EL

Example: #{bindings.Products.rangesize}
5 - 21

Copyright 2008, Oracle. All rights reserved.

Identifying Types of Bindings


There are several types of generic bindings.

5 - 22

Copyright 2008, Oracle. All rights reserved.

Types of Bindings: Attribute


Attribute binding binds the inputText component to a String value. In this example, the binding has a validate method that must be called before the binding is updated. Use the <af:validator> tag to call this method.

<af:inputText value=#{bindings.ProductName.inputValue}> <f:validator binding=#{bindings.ProductName.validator}/> </af:inputText>

Boolean attribute binding: Convert between any underlying database type (0 or 1, true or false, yes or no, and so on) and a primitive Boolean object.

<af:selectBooleanCheckbox value=#{bindings.ContactableFlag.inputValue}/>

5 - 23

Copyright 2008, Oracle. All rights reserved.

Types of Bindings: Table


Table binding:
<af:table value="#{bindings.OrdersView2.collectionModel}" var="row" rows="#{bindings.OrdersView2.rangeSize} emptyText="#{bindings.OrdersView2.viewable ? 'No rows yet.' : 'Access Denied.'}" fetchSize="#{bindings.OrdersView2.rangeSize}"> <af:column sortProperty="OrderId" sortable="false" headerText="#{bindings.OrdersView2.hints. OrderId.label}"> <af:outputText value="#{row.OrderId}"> <af:convertNumber groupingUsed="false" <tree IterBinding="OrdersView2Iterator" pattern="#{bindings.OrdersView2. id="OrdersView2"> hints.OrderId.format}"/> <nodeDefinition DefName="demomodel. </af:outputText> queries.OrdersView"> </af:column> <AttrNames> <af:column <Item Value="OrderId"/> ... ... </af:table> </AttrNames> </nodeDefinition> </tree>

5 - 24

Copyright 2008, Oracle. All rights reserved.

Types of Bindings: List


List binding: Exports a list of legal values, enabling the user to select one
<af:selectOneChoice value="#{bindings.SupplierStatus.inputValue}" label="#{bindings.SupplierStatus.label}" required="#{bindings.SupplierStatus.hints.mandatory}" testId="selectOneChoice1"> <f:selectItems value="#{bindings.SupplierStatus.items}"/> </af:selectOneChoice>

<list IterBinding="Supplier1Iterator" Uses="LOV_SupplierStatus" id="SupplierStatus" DTSupportsMRU="false"/>

5 - 25

Copyright 2008, Oracle. All rights reserved.

Types of Bindings: Action


Action binding example: A binding to an ADFm built-in operation (can also bind to a business method)

<af:commandButton actionListener=#{bindings.Commit.execute} disabled=#{!bindings.Commit.enabled}/>

<action id="Commit" InstanceName="SupplierDataControl" DataControl="SupplierDataControl" RequiresUpdateModel="true" Action="commitTransaction"/>

5 - 26

Copyright 2008, Oracle. All rights reserved.

Using View-Level Operations in Action Bindings: Setting the Current Row


setCurrentRowWithKey:
The rowKey parameter is a serialized view row key, such as: 000200000002C20200000002C102000000010000010A5AB 7DAD9
For example: #{bindings.SomeAttrName.rowKeyStr} #{row.rowKeyStr}

setCurrentRowWithKeyValue:
The rowKey parameter is the literal key value for a single-attribute key. For example, 1001 is used to find the order number 1001.

5 - 27

Copyright 2008, Oracle. All rights reserved.

Using View-Level Operations in Action Bindings: Inserting a New Row


Use CreateInsert for: An editable table control A table with a single, current editable row A master or detail page, if you want the newly created master row to correctly show no existing detail rows

5 - 28

Copyright 2008, Oracle. All rights reserved.

Create and CreateInsert


The Create operation performs the following code:

// create a new row for the view object Row newRow = yourViewObject.createRow(); // mark the row as being "initialized", but not yet new newRow.setNewRowState(Row.STATUS_INITIALIZED);

In addition, the CreateInsert operation performs:

// insert new row into view object's default rowset yourViewObject.insertRow(newRow);

5 - 29

Copyright 2008, Oracle. All rights reserved.

Binding Objects in the Executables Section


The executables element of the page definition file defines the following types of executable binding objects:
iterator: Is the basic link from data to binding methodIterator: Links the results of a method call to a binding accessorIterator: Links to detail collections for nested objects variableIterator: Accesses data, which is local to the page definition file invokeAction: Allows automatic life-cycle invocation of method binding

5 - 30

Copyright 2008, Oracle. All rights reserved.

Controlling the Execution of Executables


Executables are evaluated in the order in which they appear in the page definition file. Executables may be further controlled by using:

The Refresh property: Executes when in the life cycle RefreshCondition and RefreshAfter: Whether to execute

Example:
RefreshCondition= "${(CartBean.cartId != null || orderBean.status == OPEN}"

Note: Pay attention to side effects. Double invocation when bindings are based on a method iterator implicitly invoke the method.

5 - 31

Copyright 2008, Oracle. All rights reserved.

Leveraging Iterators
Working with multiple row sets and row set iterators: Use View Object as the default row set. Create secondary row sets based on the same VO. Create multiple row sets for different bind variable values.
The following methods are available:

createRowSet()

createRowSetIterator() findRowSetIterator() closeRowSetIterator()

closeRowSetIterator()

5 - 33

Copyright 2008, Oracle. All rights reserved.

Binding Objects in the Parameters Section


The parameters element of the page definition file defines the parameters for the page. Parameter binding objects declare the parameters that the page evaluates at the beginning of a request. Page parameters are evaluated once during the Prepare Model phase. Define the value of a parameter in the page definition file by using:
Static values Binding expressions An EL expression, which assigns a static value

5 - 34

Copyright 2008, Oracle. All rights reserved.

Agenda
Defining ADF Model binding Describing the scope and role of the binding files Managing data-bound components with the page definition file Data control and Business Components (BC)

5 - 35

Copyright 2008, Oracle. All rights reserved.

Data Controls and Standard Metadata Interfaces


Data controls describe Business Services by using standard metadata interfaces.
Application Module Data controls

View Object instances in the active data model Custom method in the client interface Method arguments Data controls created from Java classes (beans)
5 - 36

Application module operations

Copyright 2008, Oracle. All rights reserved.

Working with Named Bind Variables


Two alternative ways of working with bind variables:
Using the custom VO finder operation Using the built-in ExecuteWithParams operation

5 - 37

Copyright 2008, Oracle. All rights reserved.

Transaction Control Operations


Built-in transaction control operations are:
Generic operations Usable with any View Object component

Built-in transaction control operations

5 - 38

Copyright 2008, Oracle. All rights reserved.

Schematic Representation of a Query Process

7
1 2 3 9 5 4 8 6

5 - 39

Copyright 2008, Oracle. All rights reserved.

Summary
In this lesson, you should have learned how to: Describe the scope and role of the binding files Define ADF Model binding types Define ADF Model executables and how to use them Manage data-bound components with the page definition file Bind data using EL

5 - 40

Copyright 2008, Oracle. All rights reserved.

Practice 5 Overview: Implementing Data Binding Concepts


This practice covers the following topics: Diagnosing an application problem Building binding manually

5 - 41

Copyright 2008, Oracle. All rights reserved.

Vous aimerez peut-être aussi