New Sample Demonstrating the Traversing of Tree Bindings
- by Duncan Mills
A technique that I seem to use a fair amount, particularly
in the construction of dynamic UIs is the use of a ADF Tree Binding to encode a
multi-level master-detail relationship
which is then expressed in the UI in some kind of looping form – usually a
series of nested af:iterators, rather than the conventional tree or treetable.
This technique exploits two features of the treebinding. First the fact that an
treebinding can return both a collectionModel as well as a treeModel, this
collectionModel can be used directly by an iterator. Secondly that the “rows”
returned by the collectionModel themselves contain an attribute called .children.
This attribute in turn gives access to a collection of all the children of that
node which can also be iterated over.
Putting this together you can represent the data encoded
into a tree binding in all sorts of ways.
As an example I’ve put together a very simple sample based
on the HT schema and uploaded it to the ADF Sample project. It produces this
UI:
The important code is shown here for a Region -> Country -> Location Hierachy:
<af:iterator id="i1" value="#{bindings.AllRegions.collectionModel}" var="rgn">
<af:showDetailHeader text="#{rgn.RegionName}" disclosed="true" id="sdh1">
<af:iterator id="i2" value="#{rgn.children}" var="cnty">
<af:showDetailHeader text="#{cnty.CountryName}" disclosed="true" id="sdh2">
<af:iterator id="i3" value="#{cnty.children}" var="loc">
<af:panelList id="pl1">
<af:outputText value="#{loc.City}" id="ot3"/>
</af:panelList>
</af:iterator>
</af:showDetailHeader>
</af:iterator>
</af:showDetailHeader>
</af:iterator>
You can download the entire sample from here: