New Sample Demonstrating the Traversing of Tree Bindings

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:

Example output from this technique

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:

Comments:

The link to download the source is broken - it should have "content" in it instead of "conten".

Posted by Dan on July 05, 2012 at 04:08 PM BST #

Hi
your link is not working right now as there is a "t" missing in content folder. My be you could correct it

http://java.net/projects/smuenchadf/sources/samples/conten/ExplodedTreeBindingAccessedByIterator.zip

Thanks
-Pradip

Posted by Praidp on July 05, 2012 at 05:19 PM BST #

Fixed - thanks folks!

Posted by Duncan on July 06, 2012 at 08:06 AM BST #

How would this work if you have, for example, 2 detail tables for any particular master table, like if region contain both countries and territories? ADF won't know which one to iterate over with rgn.children - in my tests, it just gives you a list of string values of the child view objects, and I can't drill into those to get their attribute values.

Posted by Dan on July 06, 2012 at 05:33 PM BST #

You can discriminate at a particular level in the tree using node definition which can be accessed thus: #{childIterator.hierTypeBinding.viewDefName} where childIterator is the var you've used in the parent iterator.
This expression will return the DefName ID that you see associated with the node in the TreeBinding (<nodeDefinition DefName="oracle.demo.model.queries.queries.CountriesView" ...>)
So you can use a switcher or the rendered attribute based on this expression.

Posted by Duncan on July 11, 2012 at 11:26 AM BST #

Post a Comment:
Comments are closed for this entry.
About

Hawaii, Yes! Duncan has been around Oracle technology way too long but occasionally has interesting things to say. He works in the Development Tools Division at Oracle, but you guessed that right? In his spare time he contributes to the Hudson CI Server Project at Eclipse
Follow DuncanMills on Twitter

Note that comments on this blog are moderated so (1) There may be a delay before it gets published (2) I reserve the right to ignore silly questions and comment spam is not tolerated - it gets deleted so don't even bother, we all have better things to do with our lives.
However, don't be put off, I want to hear what you have to say!

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today