Skip Headers
Oracle® Application Development Framework Developer's Guide
10g Release 3 (10.1.3)
B25386-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

13.7 Adding ADF Bindings to Trees and Tree Tables

You can add ADF bindings to ADF Faces tree and tree table components. The ADF Faces tree component displays a hierarchy of master-detail related data collections in a tree format. A databound ADF Faces tree displays multiple root nodes that are populated by a binding on a master data collection. Each node in the tree may have any number of branches, which are populated by bindings on detail data collections. Each node in the tree is indented to show its level in the hierarchy. The ADF tree component includes mechanisms for expanding and collapsing the tree. By default, the icon for each node in the tree is a folder; however, you can use your own icons for each level of nodes in the hierarchy. The ADF Faces tree table components display a hierarchy of master-detail collections in a table. For more information about master-detail relationships and trees, see Chapter 8, "Working with Master-Detail Relationships".

13.7.1 How to Add ADF Bindings to Trees and Tree Tables

To add ADF bindings to a tree or tree table, you drag a master data collection from the Data Control Palette and drop it on the tree tag displayed in the Structure window. For general tips about dropping items from the Data Control Palette onto the Structure window, see Section 13.1.1, "How to Add ADF Bindings to Components Using the Data Control Palette".

To add ADF bindings to a tree component:

  1. With the page displayed in the Design page of the visual editor, open the Structure window.

  2. In the Design page of the visual editor, select the tree component. The tag selected in the Structure window must be one of the tags listed previously in Table 13-1. JDeveloper simultaneously selects the corresponding tag in the Structure window. If the incorrect tag is selected, make the adjustment in the Structure window. For example, if the tree facets tag is selected, select the tree tag instead.

  3. From the Data Control Palette, drag a data collection to the Structure window and drop it on the selected tree tag. The data collection you select should be the master collection, which will populate the root node of the tree.

  4. On the Data Control Palette context menu, choose Bind Existing Tree.

  5. Use the Tree Binding Editor to define the root and branch nodes of the tree. For information about using the Tree Binding Editor to define lists, see Section 8.4, "Using ADF Databound Trees to Display Master-Detail Relationships".

13.7.2 What Happens When You Add ADF Bindings to a Tree or Tree Table

Example 13-13 displays a tree before the ADF bindings are added. Notice that the value attribute specifies the root node as users, and the var attribute specifies the first branch as service requests.

Example 13-13 ADF Faces Tree Before ADF Bindings

<af:tree value="users" var="service requests">
   <f:facet name="nodeStamp">
      <h:outputText/>
   </f:facet>
</af:tree>

Example 13-14 displays the same tree after the User data collection from the SRDemo data control was dropped on it. The User collection is returned by the findAllStaff method. The User data collection will populate the root node, and the serviceRequests collection was defined as a branch off the root nodes. The binding replaced the value attribute with a binding on the findAllStaff1 iterator. The var attribute now contains a value of node, which provides access to the current node. The nodes themselves are defined in the page definition file.

Example 13-14 ADF Faces Tree After ADF Bindings Are Added

<af:tree value="#{bindings.findAllStaff1.treeModel}" var="node">
   <f:facet name="nodeStamp">
      <af:outputText value="#{node}"/>
   </f:facet>
</af:tree>

In addition to adding the bindings to the tree, JDeveloper automatically adds several binding objects for the tree to the page definition file, as shown in Example 13-15. The iterator binding objects in the executables element define the iterators that return the collection that populates the root node, which, in the example, is findAllStaffIter.

The bindings element contains a methodAction binding object, which encapsulates the information needed to invoke the method that populates the root node. In the value bindings, the tree is bound to the findAllStaffIter iterator. Each attribute returned by the iterator is listed in the AttrNames element, but only the attributes in the nodeDefinition element are displayed in the tree. The Accesssors element defines the accessor methods that will be used to retrieve the data that will populate the branches in the node. In the example, the User node, which is the root node, defines serviceRequestCollectionAssignedTo as the accessor method. This method returns the service requests for each user node.

For more information about trees and tree tables, see Chapter 8, "Working with Master-Detail Relationships".

Example 13-15 Bindings Added to the Page Definition File for an ADF Faces Tree

<executables>
  <methodIterator id="findAllStaffIter" Binds="findAllStaff.result"
                    DataControl="SRPublicFacade" RangeSize="10"
                    BeanClass="oracle.srdemo.model.User"/>
</executables>
<bindings>
    <methodAction id="findAllStaff" InstanceName="SRPublicFacade.dataProvider"
                  DataControl="SRPublicFacade" MethodName="findAllStaff"
                  RequiresUpdateModel="true" Action="999"
                  ReturnName="SRPublicFacade.methodResults.SRPublicFacade_
                       dataProvider_findAllStaff_result"/>
    <tree id="findAllStaff1" IterBinding="findAllStaffIter">
      <AttrNames>
        <Item Value="city"/>
        <Item Value="countryId"/>
        <Item Value="email"/>
        <Item Value="firstName"/>
        <Item Value="lastName"/>
        <Item Value="postalCode"/>
        <Item Value="stateProvince"/>
        <Item Value="streetAddress"/>
        <Item Value="userId"/>
        <Item Value="userRole"/>
      </AttrNames>
      <nodeDefinition DefName="oracle.srdemo.model.User" id="UserNode">
        <AttrNames>
          <Item Value="firstName"/>
          <Item Value="lastName"/>
        </AttrNames>
        <Accessors>
          <Item Value="serviceRequestsCollectionAssignedTo"/>
        </Accessors>
      </nodeDefinition>
      <nodeDefinition DefName="oracle.srdemo.model.ServiceRequest"
                      id="ServiceRequestNode">
        <AttrNames>
          <Item Value="assignedDate"/>
          <Item Value="problemDescription"/>
          <Item Value="status"/>
        </AttrNames>
      </nodeDefinition>
    </tree>
</bindings>