Binding Data in an Application

8

Copyright © 2007, Oracle. All rights reserved.

Objectives
After completing this lesson, you should be able to do the following: • Describe the Application Development Framework (ADF) Model • Define the architecture and components of the ADF Model • Create and use data controls • Create and edit data bindings

8-2

Copyright © 2007, Oracle. All rights reserved.

ADF Architecture
ADF Swing Swing JSP ADF Controller Struts JSF ADF Faces JSF View

Controller

ADF Model XML Web Services EJB + TopLink ADF Business Components JavaBeans

Model Business Services

8-3

Copyright © 2007, Oracle. All rights reserved.

ADF Model (ADF Databinding)
ADF Model: • Provides a wrapper and abstraction for business services • Enables you to work the same way with any UI and any business service • Decouples UI from back-end business services • Provides dragand-drop databinding
8-4 Copyright © 2007, Oracle. All rights reserved.

Types of Data Controls
• • • • • • EJB session beans TopLink ADF Business Components Web services JavaBeans URL (XML or CSV data)
ADF Model XML Web services EJB + TopLink ADF Business Components JavaBeans Model Business Services

8-5

Copyright © 2007, Oracle. All rights reserved.

Model Layer Components
• Data controls describe the public interface of a business service. Bindings connect UI components to data or actions. Data controls and bindings are defined using XML metadata.

Bindings

Bindings

Data control

Business service

8-6

Copyright © 2007, Oracle. All rights reserved.

Creating a Data Control
• From the Applications Navigator:
– Select Create Data Control in the component’s shortcut menu. OR – Drag the component to the Data Control Palette.

8-7

Copyright © 2007, Oracle. All rights reserved.

Generated Files in the Data Model Project
• Structure definition file:
– For example, Products.xml – It describes the attributes of each bean or component.

Data control description file:
– DataControls.dcx – It describes the properties of all data controls in the project.

The Data Control Palette is a visual representation of the information in these files.
Copyright © 2007, Oracle. All rights reserved.

8-8

Data Control Palette
It is a visual representation of your business service that contains: • Methods • Parameters and results • Attributes • Collections • Built-in operations

8-9

Copyright © 2007, Oracle. All rights reserved.

Creating Bindings
Bindings define the interaction between a view or controller component and the data control. They : • Are created automatically when you drag a component from the Data Control Palette to a page or panel • Can also be created in the Structure window
e-mail: neena.kochhar@ Name: Kochhar

8-10

Copyright © 2007, Oracle. All rights reserved.

Types of Bindings
• • Iterator binding: Keeps track of the current row in a data collection Value binding:
– Connects UI components to attributes in a data collection – Examples: Attribute binding, tree binding, list binding, table binding

Action binding: Invokes a method or operation

8-11

Copyright © 2007, Oracle. All rights reserved.

Generated Files in the View Project
When data bindings are created, two files are generated in the UI project: • Binding context definition file:
– DataBindings.cpx – It maps pages to page definitions and declares data control usages.

Page definition file:
– xxxPageDef.xml – It defines all the bindings for a page. – It is created automatically when you add a data-bound component to a page. – It replaces the UI model file in previous versions.

8-12

Copyright © 2007, Oracle. All rights reserved.

Examining the DataBindings.cpx File
Contains JSP page definition mappings

Defines all data controls used

8-13

Copyright © 2007, Oracle. All rights reserved.

ADF Binding
• ADF pages can create value bindings to the ADF binding container using Expression Language (EL), accessing the bindings object.
#{bindings.firstName.inputValue}

• • •

The bindings object is created by the ADF servlet filter that is defined in the web.xml file. The ADF servlet filter is mapped to *.jsp and *.jspx file types. The bindings object needs to be configured as a managed property before it can be used in Managed Beans.
Copyright © 2007, Oracle. All rights reserved.

8-14

Objects and Metadata Files
Page definition file *PageDef.xml Binding context Data control description file DataControls.dcx DataBindings.cpx
8-15 Copyright © 2007, Oracle. All rights reserved.

Binding container

Data control

Structure definition file *.xml

Binding context definition file

Opening a Page Definition File
pagenamePageDef.xml (for example, searchPageDef.xml): • Contains all the binding definitions for a page • Is created automatically when you add a data-bound component to a page • To open a page definition: 1. Right-click in the editor. 2. Select Go to Page Definition.
8-16 Copyright © 2007, Oracle. All rights reserved.

Editing a Page Definition File
• • The file is displayed in the Code Editor. Elements are displayed in the Structure window.

8-17

Copyright © 2007, Oracle. All rights reserved.

Editing Bindings
• To open the editor dialog box from:
– The page: In the Visual Editor, right-click the component and select Edit Binding. – The page definition file: In the Structure window, double-click the binding.

Each type of binding has a specific editor.

8-18

Copyright © 2007, Oracle. All rights reserved.

Expression Language (EL) and Bindings
• • • • Databinding expressions are written using EL. These are evaluated at run time to determine what data to display. ADF EL expressions typically have the form:
#{bindingVariable.BindingObject.propertyName}

Example of an inputText component on a JSF page:
<af:inputText value="#{bindings.Ename.inputValue}" label="#{bindings.Ename.label}" required="#{bindings.Ename.mandatory}">

8-19

Copyright © 2007, Oracle. All rights reserved.

Accessing Bindings Programmatically
• • Use methods in DCBindingContainer. Example of getting an attribute from an iterator binding:

DCBindingContainer bc = getBindingContainer(); String empname = (String)bc .findIteratorBinding("empIter") .getCurrentRow() .getAttribute("EmpName");

8-20

Copyright © 2007, Oracle. All rights reserved.

Accessing Data Controls Programmatically
• • Use methods in DCBindingContainer. Example of accessing a ServiceRequests object from the bindingContainerBC application module:

DCBindingContainer bc = (DCBindingContainer)getBindings(); DCControlBinding thisSRId = (DCControlBinding)bc.getControlBinding("svrId"); RowImpl srRowImpl = (RowImpl)thisSRId.getCurrentRow(); ServiceRequests thisSR = (ServiceRequests)srRowImpl.getDataProvider();
8-21 Copyright © 2007, Oracle. All rights reserved.

Understanding the Bindings On a Page
Example: A simple page to browse and search users 1. Enter a search string. 2. Click Go. 3. Use Next and Previous to step through results.
Data control

8-22

Copyright © 2007, Oracle. All rights reserved.

Search Page Bindings
• • The Go button uses a method binding to call findUsersByName(). The value of the name parameter comes from the text field, using an attribute binding.
Binding container Page ( ) Data control

8-23

Copyright © 2007, Oracle. All rights reserved.

Search Page Bindings
• The results come from User, the List object returned by the method. An iterator binding keeps track of the current row. The Last Name field is bound to the lastname attribute, using an attribute binding.
Page Binding container ( ) Data control

8-24

Copyright © 2007, Oracle. All rights reserved.

Search Page Bindings
• The Next button uses an operation binding to call the Next operation, which increments the current row in the iterator binding. The table is bound to the expertiseAreas collection, using a table binding.
Page Binding container ( ) Data control

8-25

Copyright © 2007, Oracle. All rights reserved.

Drag-and-Drop Usability
• • “Drop as” context menu New table and form dialogs: Customize your form or table when you create it. Drop a method call as an input form: Fields are generated for the method parameters. Drop a parameterized view object as a parameter form. Keyboard accessibility: You can copy and paste.
Copyright © 2007, Oracle. All rights reserved.

• •

8-26

ADF Binding: Summary
DataControls.dcx <session bean>.xml <bean name>.xml

Model project

DataBindings.cpx <pagename>PageDef.xml web.xml faces-config.xml adf-faces-config.xml adf-faces-skins.xml

View project

8-27

Copyright © 2007, Oracle. All rights reserved.

Summary
In this lesson, you should have learned how to: • Describe the ADF Model • Define the architecture and components of the ADF Model • Create and use data controls • Create and edit data bindings

8-28

Copyright © 2007, Oracle. All rights reserved.

Practice Overview: Using Databinding
This practice covers the following topics: • Creating a data control • Editing a data binding • Using a data control in a simple JSF

8-29

Copyright © 2007, Oracle. All rights reserved.

8-30

Copyright © 2007, Oracle. All rights reserved.

Sign up to vote on this title
UsefulNot useful