5-10 Java EE Developers Guide for Oracle Application Development Framework
5. In the Tree Level Rules list, select the data source you just added.
6. Select an attribute in the Available Attributes list and move it to the Display
Attributes list.
The attribute will be used to display nodes at the master level. After defining a rule for the master level, you must next define a second rule for
the detail level that will appear under the master level in the tree.
7. To add a second rule, click the Add icon above the Tree Level Rules list.
A detail data source should appear automatically under the master data source, as shown in
Figure 5–6 .
Figure 5–6 Master-Detail Tree Level Rules
For example, if you specified ProductFindAll as the master root data source, WarehouseStockLevelList
will automatically appear underneath in the Tree Level Rules
list, because the two data sources share a master-detail relationship. If you are creating a tree with a recursive master-detail hierarchy, then you only
need to define a rule that specifies a data source with a self-accessor. A recursive tree displays root nodes based on a single collection and displays the child nodes
from the attributes of a self-accessor that recursively fetches data from that collection. The recursive tree differs from a typical master-detail tree because it
requires only a single rule to define the branches of the tree. A recursive data source should display the data source followed by the name of the self-accessor in
brackets, as shown in
Figure 5–7 .
Figure 5–7 Recursive Tree-Level Rule
For example, in a collection defined by EmployeesView, the root node of each branch could be specified by the ManagerId for the employee, and the child
nodes of the same branch would then be the employees who are related to the ManagerId
, as specified by the self-accessor DirectReports.
8. Click OK.
9. You can add data sources to the Tree Level Rules list to increase the number of
nodes that display in the tree. The order of the remaining data sources should follow the hierarchy of the nodes you want to display in the tree.
5.4.2 What Happens When You Create an ADF Databound Tree
When you drag and drop from the Data Controls panel, JDeveloper does many things for you.
Displaying Master-Detail Data 5-11
When you create a databound tree using the Data Controls panel, JDeveloper adds binding objects to the page definition file, and it also adds the tree tag to the JSF page.
The resulting UI component is fully functional and does not require any further modification.
5.4.2.1 Code Generated in the JSF Page
Example 5–2 shows the code generated in a JSF page when you use the Data Controls
panel to create a tree. This sample tree displays the order numbers as the root nodes and the product names as the leaf nodes.
Example 5–2 Code Generated in the JSF Page for a Databound Tree
af:tree value={bindings.orderItemFindAll.treeModel}
var=node selectionListener={bindings.orderItemFindAll.treeModel.makeCurrent}
rowSelection=single id=orderItemsTree f:facet name=nodeStamp
af:outputText value={node} id=ot2 f:facet
af:tree
By default, the af:tree tag is created inside a form. The value attribute of the tree tag contains an EL expression that binds the tree component to the
orderItemFindAll tree binding object in the page definition file. The treeModel
property in the binding expression refers to an ADF class that defines how the tree hierarchy is displayed, based on the underlying data model. The var attribute
provides access to the current node.
In the f:facet tag, the nodeStamp facet is used to display the data for each node. Instead of having a component for each node, the tree repeatedly renders the
nodeStamp facet, similar to the way rows are rendered for the ADF Faces table
component. The ADF Faces tree component uses an instance of the
oracle.adf.view.faces.model.PathSet class to display expanded nodes. This
instance is stored as the treeState attribute on the component. You may use this instance to programmatically control the expanded or collapsed state of an element in
the hierarchy. Any element contained by the PathSet instance is deemed expanded. All other elements are collapsed.
5.4.2.2 Binding Objects Defined in the Page Definition File
Example 5–3 shows the binding objects defined in the page definition file for the ADF
databound tree.
Example 5–3 Binding Objects Defined in the Page Definition File for a Databound Tree
executables variableIterator id=variables
iterator Binds=root RangeSize=25 DataControl=SupplierFacadeLocal id=SupplierFacadeLocalIterator
accessorIterator MasterBinding=SupplierFacadeLocalIterator Binds=orderItemFindAll RangeSize=25
DataControl=SupplierFacadeLocal BeanClass=oracle.fodemo.supplier.model.OrderItem
id=orderItemFindAllIterator executables
bindings
5-12 Java EE Developers Guide for Oracle Application Development Framework
tree IterBinding=orderItemFindAllIterator id=orderItemFindAll nodeDefinition DefName=oracle.fodemo.supplier.model.OrderItem
Name=orderItemFindAll0 AttrNames
Item Value=orderId AttrNames
Accessors Item Value=product
Accessors nodeDefinition
nodeDefinition DefName=oracle.fodemo.supplier.model.Product Name=orderItemFindAll1
AttrNames Item Value=productName
AttrNames nodeDefinition
tree bindings
The tree element is the value binding for all the attributes displayed in the tree. The iterBinding
attribute of the tree element references the iterator binding that populates the data in the tree. The AttrNames element within the tree element
defines binding objects for all the attributes in the master collection. However, the attributes that you select to appear in the tree are defined in the AttrNames elements
within the nodeDefinition elements.
The nodeDefinition elements define the rules for populating the nodes of the tree. There is one nodeDefinition element for each node, and each one contains the
following attributes and subelements:
■
DefName : An attribute that contains the fully qualified name of the data collection
that will be used to populate the node
■
id : An attribute that defines the name of the node
■
AttrNames : A subelement that defines the attributes that will be displayed in the
node at runtime
■
Accessors : A subelement that defines the accessor attribute that returns the next
branch of the tree The order of the nodeDefintion elements within the page definition file defines the
order or level of the nodes in the tree, where the first nodeDefinition element defines the root node. Each subsequent nodeDefinition element defines a subnode
of the one before it.
5.4.3 What Happens at Runtime: Displaying an ADF Databound Tree