16-ADF Binding
16-ADF Binding
Section 16
Oracle ADF – Binding Layer
What Is Data Binding?
Desktop Browser-Based
St t
Struts JSF/ADF Controller
C t ll Controller
Desktop Browser-Based
St t
Struts JSF/ADF Controller
C t ll Controller
Databinding Layer M d l
Model
Datacontrol Layer
ADF Binding
Expr. Language “bindings” Object
ADF DataControl
Ajax Render
Kit UI Component
Client
RDBMS
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF
Application Module
View Object
Cli t Method
Client M th d
Operation
Nested Application
Module
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF
Data bindings
Data controls
Business Services
ADF Model Overview
What is a binding?
A binding exposes a property or table from the underlying
model in a generic Expression Language (EL)–accessible
way.
<af:inputText
< f i tT t value=
l
Text
“#{bindings.Ename.inputValue}”>
Binding
<af:commandButton
Action
Binding
actionListener=
Data ADFM
“#{bindings.Commit.execute}”>
control Bindings
<af:selectItems items=
List
“#{bindings.Deptno.items}”>
Binding
<af:table value=
Tree “#{bindings.DeptView.collectionModel}”>
Binding
ADF Model Overview
Table
#{bindings.DeptView}
g p binding
ADF Binding in the ADF Faces UI
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF
PageDef
g – The Data
Binding Configuration
PageDef.xml File
Several types
y of g
generic bindings:
g
Types of Bindings: Attribute
Attribute binding
g example:
• Binds 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
binding= #{bindings.ProductName.validator}
ProductName validator}”/>
/>
</af:inputText>
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}"> PageDef
<af:outputText value="#{row.OrderId}"><tree IterBinding="OrdersView2Iterator"
<af:convertNumber id="OrdersView2">
groupingUsed="false" <nodeDefinition DefName="demomodel.
queries.OrdersView">
pattern="#{bindings.OrdersView2.hints.OrderId.format}"/>
<AttrNames>
</af:outputText> <Item Value="OrderId"/>
</af:column> ...
... </AttrNames>
</af:table> </nodeDefinition>
</tree>
Types of Bindings: List
List binding:
g Exports a list of legal
g values, enabling
g the
user to select one.
<af:selectOneChoice
value #{bindings.SupplierStatus.inputValue}
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"
id= SupplierStatus DTSupportsMRU=
DTSupportsMRU="false"/>
false />
Types of Bindings: Action
<af:commandButton actionListener=“#{bindings.Commit.execute}”
disabled=“#{!bindings.Commit.enabled}”/>
DEMO
Structure
Definition(s)
Page Definition(s) Binding Container Data Control
*.xml
*PageDef.xml
• Bindings
g are defined in XML at designtime
g
• Binding objects are created at Runtime
• Generic Binding classes start with "JUCtrl"
• Specific ADF Faces binding classes start with
"FacesCtrl"
• Adapt the generic binding layer to component model
requirements
• Expose extra methods to be used in action listeners
• makeCurrent
• Labels
• Developers usually work with a subset of these classes
Class Diagram
Example: Accessing the Binding
Container from Java
import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;
…
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = null;
bindings = bctx.getCurrentBindingsEntry();
Example: Executing a Method Binding
in Java
import oracle.binding.OperationBinding;
import oracle.jbo.domain.Number;
…
DCBindingContainer bindingsImpl = (DCBindingContainer)
bctx.getCurrentBindingsEntry();
OperationBinding relocateEmployees = null;
relocateEmployees = bindings.getOperationBinding("relocateEmployees");
HashMap<Number,Number> emps = new HashMap<Number,Number>();
emps.put(new Number(103),new Number(90));
emps.put(new Number(104),new Number(90));
emps.put(new Number(105),new Number(100));
relocateEmployees.getParamsMap().put("employees",emps);
relocateEmployees execute();
relocateEmployees.execute();
Example: Changing the value of an
Attribute Binding in Java
import oracle.binding.AttributeBinding;
…
AttributeBinding departmentName =
(AttributeBinding) bindings.get ("DepartmentName");
String oldValue = (String) departmentName.getInputValue();
String newValue = oldValue+"_new";
departmentName.setInputValue(newValue);
Example: Reading attributes from a
List Binding in Java
import oracle.jbo.uicli.binding.JUCtrlListBinding;
import oracle.jbo.domain.Number;
…
JUCtrlListBinding listBinding = null;
listBinding = (JUCtrlListBinding) bindings.get("JobId");
ViewRowImpl selectedListRow = null;
selectedListRow = (ViewRowImpl) listBinding.getSelectedValue();
String jobIdValue = (String) selectedListRow.getAttribute("JobId");
Number maxSalary = (Number) selectedListRow.getAttribute("MaxSalary");
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF
Dataco
W
Bind
S Place Order
ding
ontrol
ADF D
Swing L
JSP
Web Service Datacontrol: Step-by-Step