Monday, June 18, 2012

What Happens When You Create a ADF Page and Use the Data Controls Panel : ADF Insight View


It is not over when it comes to ADF View Controller .You created a page , it runs and you enjoy seeing the output .The Fact is ADF creates a lot of XML files for each file you create and all files have reference to it . If any of these files are misplaced or removed then you will have tough time to debug and you will end up creating the project again .  so in the way , i will tell you about what are the files will be created and updated when you create a jsf page fragment , jspx page and using a data control to bring up the populated data.

Before starting, have a look at this post how-to-create-oracle-adf-page . I will explain the concepts based on the post so that it will be useful to understand

DataBindings.cpx

what is Page Definition file ?

when you create jsp file and drop a data control on to  a page , ADF View controller creates another file called PageDef.xml to store all the bindings , collection model it uses and the iterator defined.




Suppose in our case we dropped  employees data control on the sample page . Now when we look at the PageDef.xml there are three tabs for various purposed defined . Bindings section contains the Data control we used to drag and drop from the Data Control panel. here it is EmployeesVO1 .  Executables part contains the iterators for the Bindings we added . Every iterator refers a VO instance (i.e a collection) corresponding to its bindings .  The EmployeesVO1 uses EmployeesVO1Iterator to loop the data and print in the page .( for ex : when we have a java arraylist that contains data and we use iterator to loop and print it accordingly. The real use will be like this in a page #{bindings.EmployeesVO1Iterator.estimatedRowCount})
You can even create a new ADF binding on the fly and make use of it through EL.

Source code for the SamplePageDef.xml

<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
                version="11.1.1.61.92" id="SamplePageDef" Package="pages">
  <parameters/>
  <executables>
    <variableIterator id="variables"/>
    <iterator Binds="EmployeesVO1" RangeSize="25"
              DataControl="AppModuleDataControl" id="EmployeesVO1Iterator"/>
  </executables>
  <bindings>
    <tree IterBinding="EmployeesVO1Iterator" id="EmployeesVO1">
      <nodeDefinition DefName="model.view.EmployeesVO" Name="EmployeesVO10">
        <AttrNames>
          <Item Value="CommissionPct"/>
          <Item Value="DepartmentId"/>
          <Item Value="Email"/>
          <Item Value="EmployeeId"/>
          <Item Value="FirstName"/>
          <Item Value="HireDate"/>
          <Item Value="JobId"/>
          <Item Value="LastName"/>
          <Item Value="ManagerId"/>
          <Item Value="PhoneNumber"/>
          <Item Value="Salary"/>
        </AttrNames>
      </nodeDefinition>
    </tree>
  </bindings>
</pageDefinition>


Now lets talk about DataBindings.cpx .



This file will be created when you create any page first time in the ADF View Controller project . This file will contains the pages you create in the ADF view controller project .  It has Page Mappings , Page Definition Usages, Data Control Usages .Page Mappings contains two sections path and usageId. Path is the location of the file in contextual path . Page Definition Usages contains the Id and path for the binding file created for a jsf or jsp page .  Data Control Usages contains the application modules

Source Code for DataBindings.cpx

<?xml version="1.0" encoding="UTF-8" ?>
<Application xmlns="http://xmlns.oracle.com/adfm/application"
             version="11.1.1.60.13" id="DataBindings" SeparateXMLFiles="false"
             Package="view" ClientType="Generic">
  <pageMap>
    <page path="/pages/Sample.jspx" usageId="view_SamplePageDef"/>
  </pageMap>
  <pageDefinitionUsages>
    <page id="view_SamplePageDef" path="pages.SamplePageDef"/>
  </pageDefinitionUsages>
  <dataControlUsages>
    <BC4JDataControl id="AppModuleDataControl" Package="model.applicationmodule"
                     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>


How the  Data is being fetched and displayed in the page using ADF bindings ?

After we create a ADF Table dropping a Data Control on the jsp page, binding section identifies the corresponding collection model associated with it and creates the iterator. Once it is done it loops through the data collection using iterator and displays the data accordingly. Look at the sample code below

<af:table value="#{bindings.EmployeesVO1.collectionModel}" var="row"
                  rows="#{bindings.EmployeesVO1.rangeSize}"
                  emptyText="#{bindings.EmployeesVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
                  fetchSize="#{bindings.EmployeesVO1.rangeSize}"
                  rowBandingInterval="0" id="t1">
    <af:column sortProperty="CommissionPct" sortable="true"
                     headerText="#{bindings.EmployeesVO1.hints.CommissionPct.label}"
                     id="c2">
            <af:outputText value="#{row.CommissionPct}" id="ot2">
              <af:convertNumber groupingUsed="false"
                                pattern="#{bindings.EmployeesVO1.hints.CommissionPct.format}"/>
            </af:outputText>
          </af:column>
</af:table >

you get a row property to uniquely identify a row representation data and access its columns data


No comments:

Post a Comment