06_ImplementingDataBinding

download 06_ImplementingDataBinding

of 40

Transcript of 06_ImplementingDataBinding

  • 8/13/2019 06_ImplementingDataBinding

    1/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.

    Implementing Data Binding Concepts

  • 8/13/2019 06_ImplementingDataBinding

    2/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 2

    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)

  • 8/13/2019 06_ImplementingDataBinding

    3/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 3

    Agenda

    Defining ADF Model binding

    Describing the scope and role of the binding files

    Managing data-bound components with the pagedefinition file

    Data control and Business Components (BC)

  • 8/13/2019 06_ImplementingDataBinding

    4/40Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 4

    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

  • 8/13/2019 06_ImplementingDataBinding

    5/40Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 5

    The Heart of ADF: ADFm

    Relational Data XML Data Packaged AppsLegacy Data

    BusinessServices

    DataServices

    Model

    Controller

    JSP View

    Desktop Browser-based

    Struts

    ADF Model (JSR-227)

    Java EJB

    Toplink

    OfficeADF Swing

    BAM ADF BC PortletBI XMLBPEL WebServices

    JSF/ADF Controller

    JSF ADF Faces

  • 8/13/2019 06_ImplementingDataBinding

    6/40Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 6

    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 UIbindings 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.

  • 8/13/2019 06_ImplementingDataBinding

    7/40Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 7

    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.

  • 8/13/2019 06_ImplementingDataBinding

    8/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 8

    Nested Application Modules

  • 8/13/2019 06_ImplementingDataBinding

    9/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 9

    Changing the Application Module

    Data Control NameYou can change the default application module name of the

    data control.

  • 8/13/2019 06_ImplementingDataBinding

    10/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 10

    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 thepage)

    Action bindings to invoke custom or built-in operations on a

    data control or its data collections (The Create button)

  • 8/13/2019 06_ImplementingDataBinding

    11/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 11

    Business Services

    User interface

    Data controls

    Data bindings

    ADFm: Data Controls and Data Bindings

  • 8/13/2019 06_ImplementingDataBinding

    12/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 12

    ADF Model: Overview

    A binding exposes a property or table from the underlying

    model in a generic EL-accessible way.

    ADFm

    bindings

    Text

    binding

    Action

    binding

    List

    binding

    Table

    binding

    Data

    control

  • 8/13/2019 06_ImplementingDataBinding

    13/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 13

    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 isin the DataBindings.cpx file.

    PageDefinition

    browsePageDef.xml

    Text

    binding

    Action

    binding

    List

    binding

    Table

    binding

    #{bindings.DeptView}

    viewId

    browse.jspx

    BindingContext

    DataBindings.cpx

  • 8/13/2019 06_ImplementingDataBinding

    14/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 14

    Agenda

    Defining ADF Model binding

    Describing the scope and role of the binding files

    Managing data-bound components with the page definitionfile

    Data control and Business Components (BC)

  • 8/13/2019 06_ImplementingDataBinding

    15/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 15

    DataBindings.cpx File

    Provides the metadata from which the Oracle ADF binding

    objects are created at run time

    Uses XML syntax Specifies:

  • 8/13/2019 06_ImplementingDataBinding

    16/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 16

    DataBindings.cpx File: Details

    Locates the correct PageDef for a page

    Defines the data control usage of the project

  • 8/13/2019 06_ImplementingDataBinding

    17/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 17

    DataBindings.cpx Properties:

    Synchronization Mode Use Immediate mode for

    performance (now the

    default). Batch mode is best reserved

    for n-tier.

  • 8/13/2019 06_ImplementingDataBinding

    18/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 18

    Agenda

    Defining ADF Model binding

    Describing the scope and role of the binding files

    Managing data-bound components with the page definitionfile

    Data control and Business Components (BC)

  • 8/13/2019 06_ImplementingDataBinding

    19/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 19

    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, orregion

    XML file content:

    Default location controlled by the ADFm Settings >PageDef subpackage project property

    Run-time location determined by the DataBindings.cpxfile (see CpxFileName in web.xml)

    Three sections (in order of interest, and not appearance):

    1. Bindings

    2. Executables

    3. Parameters

  • 8/13/2019 06_ImplementingDataBinding

    20/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 20

    Examining a Page Definition File

    The file displays in:

    The Structure pane

    The editor Three sections are displayed, with

    detailed bindings in each.

  • 8/13/2019 06_ImplementingDataBinding

    21/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 21

    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}

  • 8/13/2019 06_ImplementingDataBinding

    22/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 22

    Identifying Types of Bindings

    There are several types of generic bindings.

  • 8/13/2019 06_ImplementingDataBinding

    23/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 23

    Types of Bindings: Attribute

    Attribute binding binds the inputText component to aString value.

    In this example, the binding has a validate method thatmust be called before the binding is updated.

    Use the tag to call this method.

    Boolean attribute binding: Convert between any underlying

    database type (0 or 1, true or false, yes or no, and soon) and a primitive Boolean object.

  • 8/13/2019 06_ImplementingDataBinding

    24/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 24

  • 8/13/2019 06_ImplementingDataBinding

    25/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 25

    Types of Bindings: List

    List binding: Exports a list of legal values, enabling the user to

    select one

  • 8/13/2019 06_ImplementingDataBinding

    26/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 26

    Types of Bindings: Action

    Action binding example: A binding to an ADFm built-in

    operation (can also bind to a business method)

  • 8/13/2019 06_ImplementingDataBinding

    27/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 27

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

    setCurrentRowWithKey:

    The rowKey parameter is a serialized view row key, such as:

    000200000002C20200000002C102000000010000010A5AB7DAD9.

    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 findthe order number 1001.

  • 8/13/2019 06_ImplementingDataBinding

    28/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 28

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

    Use CreateInsert for:

    An editable table control

    A table with a single, currenteditable row

    A master or detail page if you

    want the newly created master

    row to correctly show noexisting detail rows

  • 8/13/2019 06_ImplementingDataBinding

    29/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 29

    Create and CreateInsert

    The Create operation performs the following code:

    In addition, the CreateInsert operation performs:

    // insert new row into view object's default rowset

    yourViewObject.insertRow(newRow);

    // 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);

  • 8/13/2019 06_ImplementingDataBinding

    30/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 30

    Binding Objects in the Executables Section

    The executables element of the page definition file defines thefollowing 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 amethod binding

  • 8/13/2019 06_ImplementingDataBinding

    31/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 31

    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:

    Note: Pay attention to side effects. Double invocation when bindings

    are based on a method iterator implicitly invokes the method.

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

  • 8/13/2019 06_ImplementingDataBinding

    32/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 33

    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()

  • 8/13/2019 06_ImplementingDataBinding

    33/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 34

    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 thepage 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

  • 8/13/2019 06_ImplementingDataBinding

    34/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 35

    Agenda

    Defining ADF Model binding

    Describing the scope and role of the binding files

    Managing data-bound components with the page definitionfile

    Data control and Business Components (BC)

  • 8/13/2019 06_ImplementingDataBinding

    35/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 36

    Data Controls and Standard Metadata Interfaces

    Data controls describe Business Services by using standard

    metadata interfaces.

    View Object instancesin the active data model

    Custom method in the

    client interfaceMethod arguments

    Application

    module operations

    Application Module

    Data controls

    Data controls created

    from Java classes (beans)

  • 8/13/2019 06_ImplementingDataBinding

    36/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 37

    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

  • 8/13/2019 06_ImplementingDataBinding

    37/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 38

    Transaction Control Operations

    Built-in transaction control operations are:

    Generic operations

    Usable with any View Object component

    Built-in transaction

    control operations

    S h i R i f Q P

  • 8/13/2019 06_ImplementingDataBinding

    38/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 39

    Schematic Representation of a Query Process

    1 2

    3

    4

    5

    6

    7

    8

    9

    S

  • 8/13/2019 06_ImplementingDataBinding

    39/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 40

    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

    P ti 6 O i

  • 8/13/2019 06_ImplementingDataBinding

    40/40

    Copyright 2010, Oracle and/or its affiliates. All rights reserved.6 - 41

    Practice 6 Overview:

    Implementing Data Binding Concepts

    This practice covers the following topics:

    Diagnosing an application problem

    Building binding manually