Please disable your adblock and script blockers to view this page

Search this blog

Saturday 5 July 2014

Populate af:treeTable programatically using POJO in Oracle ADF (11g & 12c)

Hello All
This post is about creating & populating af:treeTable programmatically in ADF 11g and 12c
treeTable is basically a hierarchical representation of data, using ADF model layer we can create treeTable very easily by defining master-detail relation between viewObjects
see my previous posts on treeTable-
Tree Table Component in Oracle ADF(Hierarchical Representation)
Tree Table Component with declarative presentation in ADF, Access childs without custom selection listener
Expand and Collapse an af:treeTable programmatically in ADF Faces (Oracle ADF)
Refreshing Child Nodes of an af:treeTable / af:tree in Oracle ADF

to populate treeTable programmatically we need to configure data set that fits to tree hierarchy
thanks to Chris Muir's post about programmatic creation of treeTable

there is 4-5 simple steps to do-
  • Create a fusion web application and drop a af:treeTable on page , in treeTable creation wizard select "bind later" 

  • now create managed bean to populate data in treeTable, create a simple List in managed bean of type POJO class (a java class that contains attributes and their accessor  )
  • so in this app i am going to Tv Serial and respective character names in treeTable, for that i have created a class that contains POJO for treeTable

  • import java.util.ArrayList;
    import java.util.List;
    public class Seasons {
        public Seasons(String name) {
   = name; // To Store Header Values (Storing Seasons Name :))
            characters = new ArrayList<Seasons>(); // To Store Detail Values (Storing Season's Charatcers)
        public void setCharacters(List<Seasons> empDet) {
            this.characters = empDet;
        public List<Seasons> getCharacters() {
            return characters;
        private String name;
        private List<Seasons> characters;
        public void setName(String name) {
   = name;
        public String getName() {
            return name;
    // This methods directly add characters value in list
        public void addEmp(Seasons employee) {

  • In this class the characters list behaves as child of seasons, so in managed bean define a top-level list (that contains both master and detail) and add values

  • See managed Bean Code-
    import java.util.ArrayList;
    import java.util.List;
    import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
    public class ProgrammaticTreeTabBean {
        List<Seasons> seasonList = new ArrayList<Seasons>();
        ChildPropertyTreeModel charatcerVal;
        public ProgrammaticTreeTabBean() {
            // Creating tree for Seasons and Characters details
            // Adding Master Values (seasons)
            Seasons season1 = new Seasons("Game of Thrones");
           // Adding Detail Values (Child Node-Characters)
            Seasons character = new Seasons("Tywin Lannister");
            character = new Seasons("Tyrion Lannister");
            character = new Seasons("Jaime Lannister");
            character = new Seasons("Cersie Lannister");
            character = new Seasons("Ned Stark");
            // Adding Master Values (seasons)
            Seasons season2 = new Seasons("Arrow");
            // Adding Detail Values (Child Node-Characters)
            character = new Seasons("Oliver Queen");
            character = new Seasons("Moira Queen");
            character = new Seasons("Laurel Lance");
            character = new Seasons("Sara Lance");
            // Adding Master Values (seasons)
            Seasons season3 = new Seasons("Vikings");
          // Adding Detail Values (Child Node-Characters)
            character = new Seasons("Ragnar Lothrak");
            // Adding all list to topList
            // Filtering Child Data, ChildPropertyTreeModel creates a TreeModel from a List of beans, see
            charatcerVal = new ChildPropertyTreeModel(seasonList, "characters");
        public ChildPropertyTreeModel getCharatcerVal() {
            return charatcerVal;

  • Now code part is complete, now configure your treeTable to show data, see XML source of af:treeTable

  • <af:treeTable rowBandingInterval="0" id="tt1"
                                  value="#{pageFlowScope.ProgrammaticTreeTabBean.charatcerVal}" var="node"
                                  rowSelection="single" initiallyExpanded="true">
                        <f:facet name="nodeStamp">
                            <af:column headerText="Node Stamp" id="c1" width="250">
                                <af:outputText value="#{}" id="ot1" inlineStyle="font-weight:bold;"/>

  • Now run your application and check , what you have done ;)
Happy Learning :) Sample ADF Application (12.1.3)


  1. Hi Ashish,

    Thanks for Your grate Posts from ur blog its not blog its a place i learn alot

    based on this blog I populated TreeTable

    in my case am populated using Files Class in Java with Folders
    how to add child to chaild Items

    and can U please tell me when am adding chailds the same chailds adding to every node

    Thanks and regards

    1. Raja

      Check Add and delete records (Parent/Child) in POJO Based ADF TreeTable
      This post is about adding child and parent nodes in POJO based tree
      I hope it'll help you


    2. Hi Ashish Thanks for your reply,

      your suggestion is Good but i don't want that type. as My view now we have some chailds(cherecters)we need to add sub chaild

      |-sub chaild

      I did same like Ur code and am adding values from Lists

      in MyCode am using folders and subfolders and so on..... according to directory. I loaded all values to map key as root and Chaild as value now we need to add sub chailds

      Please Help me to do that

      for more Clarity see here

      Thanks in Advance Your help is really precious to me

    3. As per above example if you want to add sub child then
      write like this -

      // Adding Master Values (seasons)

      Seasons season4 = new Seasons("Test Data");

      // Adding Detail Values (Child Node-Characters)

      character = new Seasons("Test Child");


      //Add this as child of first Record



  2. Ashish, I need pragmatical Logic Help me here its grate help if U did something and as per your example we cant Imzine root and chaild but your example giving one path to every one without your example there is no other ideas. Please help me

    Thanks AShish for your valuable example

  3. This comment has been removed by the author.

  4. Sorry ashish my code example am posting here but it was not visible here what can i do

    1. You have to call addCharacter method for every child level , Now you have to check if a directory has child directory then you have to call this method to add sub child
      I can't make a sample this time , you have to try it yourself


  5. Hi Ashish Thanks for this

    Now i got Tree according to my directory but now i have a problem on selection of those i Completely used your code for selection event

    Now the problem is

    \- chaild (Selection working)
    \-\-sub chaild(Selection not working) :-(

    1. Raja Sekhar

      You can traverse treeTable to get all nodes and to get specific node value in multi level tree you can use f:attribute tag in treeTable and on button click get that attribute value

      < f:attribute name="nodeName" value="#{}" / >

      and to get it's value in bean actionEvent.getComponent().getAttributes().get("nodeName")


  6. sorry Ashish to disturbing U again and again i tried it, it was throwing null pointer Exception

    Object obj = selectionEvent.getComponent().getAttributes().get("nodeName");
    System.out.println("Selected Obj " + obj.toString());

    1. Don't use f:attribute on selectionListener , drop a button or link in a column of treeTable and then drop f:attribute under it , Like this

      < af:column id="c2" width="30" align="center" >
      < af:link id="l1" text="Get Selected Record"
      actionListener="#{viewScope.ProgrammaticTreeTabBean.SelectedRecordAction}" >
      < f:attribute name="nodeName" value="#{}"/ >
      < / af:link >
      < / af:column >


    2. Perfect Solution Ashish. Thanks for awesome support

      now i have doubt why selection listener not supporting in this event Now if we choose one node(Link) its Refreshing means just flipping whole tree i dont want this again and again.

      any have Ur support is awesome

    3. Try setting contentDelivery property to immediate


  7. Hi Ashish

    As of our previous discussion we Implemented (n) nodes & child tree with POJO

    Now i have a one question i searched and tried so many ways but not success any way

    can we Implement Bread Crumbs Navigation with that tree. is that's possible with our implementation.


  8. Hi Ashish,Could you please help me,
    i am beginner to Oracle ADF, Could you tell me how to bind View Objects to ADF Swing Tree Component Programmatically with any simple Single table based View Object as example.

    Thank you in Advance

    1. Girdhar

      I don't have any examples on ADF Swing , You can learn same using ADF Faces