1 Oracle Jdeveloper 11G ADF Binding Internals
Total Page:16
File Type:pdf, Size:1020Kb
<Insert Picture Here> Oracle JDeveloper 11 g ADF Binding Internals: Understanding What You Are Building Frank Nimphius Principal Product Manager Oracle Application Tools Development 1 Everything beautiful has … ... something ugly that gets it going 2 Agenda • Data Controls • ADF Binding Layer • ADF Binding Classes • ADF Binding Accss from Java • Lifecycle Customization <Insert Picture Here> Data Controls 3 Data Control Concepts • Uses standard metadata interface to describe the services’ operations and data collection • At design time, simplifies binding components to data control operation or 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. ADF 11g Built-in Data Controls • ADF Business Components • Java Class • EJB • URL (XML or CSV) • Web Service • Essbase • Place Holder • Add your own 4 ADF BC Data Control Application Module View Object Client Method Operation Nested Application Module Demonstration Data Control Artifacts 5 <Insert Picture Here> The ADF Binding Layer What happens ? Simsa –––simsa –––la ---bimbimbim 6 ADF Data Bindings Concepts • Data bindings abstract the details of accessing data from data collections and of invoking its operations. • There are three kinds of declarative bindings objects: • “Iterator bindings” • to bind to an iterator that tracks the current row in a data collection (Results returned to page) • “Value bindings” • to connect UI components to attributes in a data collection (Text values entered on page) • “Action bindings” • to invoke custom or built-in operations on a data control or its data collections (Create Button) PageDef.xml File The key data binding artifact: • Is accessible via the visual editor’s 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 7 ADF Binding in the ADF Faces UI Executables • Iterators • Link other bindings to a Data Control (mostly) • Either Attributes directly or collections • Types: • Iterator – basic link data to binding • Method iterator – link the results of a method call to a binding • Accessor Iterator – link to detail collections for nested objects (not used with ADF BC) • Variable Iterator – access to local data defined in the pagedef • Most often used for method arguments • Not linked to a Data Control 8 Refresh Settings Value Meaning always Invoke on page entry or postback Only invoke if the binding is used (e.g. table may or deferred may not be rendered based on some other condition) Let ADF decide – often used with ADF BC where the ifNeeded model is "self aware" never Use when only invoking from code prepareModel See lifecycle next – also has ifNeeded variant renderModel See lifecycle next – also has ifNeeded variant What You Need to Know About Bindings • They may or may not be used in a UI • Accessed via the "bindings" object on the HTTP Request • Conventionally via Expression Language (EL) #{bindings.EmpNo} • #{bindings} provides access to everything defined in the Binding Container / PageDef • Individual bindings e.g. Table Bindings • Are objects • Have attributes *other* than value • All accessible via EL • #{bindings.Employees.rangesize} 9 Types of Bindings: Attribute Attribute binding 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.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}”/> Types of Bindings: Table Table binding: <af:table value= "#{bindings.OrdersView2.collectionModel}" var="row" 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" pattern="#{bindings.OrdersView2.hints.OrderId.format}"/> PageDef <tree IterBinding="OrdersView2Iterator" </af:outputText> id=" OrdersView2 "> </af:column> <nodeDefinition DefName="demomodel. ... queries.OrdersView"> <AttrNames> </af:table> <Item Value="OrderId"/> ... </AttrNames> </nodeDefinition> </tree> 10 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"/> Types of Bindings: Action Action binding example: This is 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"/> 11 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 using: • Static values • Binding expressions • EL expressions that assigns a static value Bindings MetaData Summary Binding Context Structure Definition(s) Page Definition(s) Binding Container Data Control *.xml *PageDef.xml Binding Context Data Control Definition Description DataBindings.cpx *.dcx 12 DataBindings.cpx File • Provides the metadata from which the Oracle ADF binding objects are created at run time • Uses XML syntax • <pageMap > • <dataControlUsages > • <pageDefinitionUsages > DataBindings.cpx <?xml version="1.0" encoding="UTF-8" ?> <Application xmlns="http://xmlns.oracle.com/adfm/application" version="…" id="DataBindings" SeparateXMLFiles="false" Package=“oracle.demo.view" ClientType="Generic"> <pageMap> <page path="/home.jspx" usageId="homePageDef"/> <page path="..." /> </pageMap> <pageDefinitionUsages> <page id="homePageDef" path="oracle.demo.view.pageDefs.homePageDef"/> <page id="..."/> </pageDefinitionUsages> <dataControlUsages> <BC4JDataControl id="AppModuleDataControl" Package="oracle.demo.model" FactoryClass="oracle.adf.model.bc4j.DataControlFactoryImpl" SupportsTransactions="true" SupportsFindMode="true" SupportsRangesize="true" SupportsResetState="true" SupportsSortCollection="true" Configuration="AppModuleLocal" syncMode="Immediate" xmlns="http://xmlns.oracle.com/adfm/datacontrol"/> </dataControlUsages> </Application> 13 Demonstration Bindings <Insert Picture Here> ADF Binding Classes 14 ADF Faces Model Integration Java EE Model Server Side Component to Business Service Data Binding Expression Model Binding Language Web Service Component POJO UI Renderer ADF BC Component EJB Model Custom POJO Binding Client Side BPEL JMX Rich Client Component TopLink Component BAM Peer ADF Faces ADF Model Integration Java EE Model Server Side Component to Business Service Data Binding Expression Model Binding Language Web Service Faces Ctrl Bindings Component ADF POJO PageDef.xml Data Data UI Renderer ADF BC Control Binding Component EJB Model Custom POJO Binding Client Side BPEL JMX Rich Client Component TopLink Component BAM Peer 15 Binding Classes – The Java in ADF Example: Accessing the Binding Container in Java import oracle.adf.model.BindingContext; import oracle.binding.BindingContainer; … BindingContext bctx = BindingContext.getCurrent(); BindingContainer bindings = null; bindings = bctx.getCurrentBindingsEntry(); 16 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(); 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); 17 Example: Reading attributes from a List Binding in Java import oracle.jbo.uicli.binding.JUCtrlListBinding;