Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label po. Show all posts
Showing posts with label po. Show all posts

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)