Question

I'm learning ADF and have a question. I have an ADF TreeTable that I want to temporarly populate with static data. I'm using a bean for this, but the TreeTable is not being populated. Can someone check the code I have and tell me if I'm doing something wrong?

My treeTable

      <af:treeTable rowBandingInterval="0" id="tt1" width="100%" value="#{viewScope.MyBean.treeData}">
        <f:facet name="nodeStamp">
          <af:column sortable="false" headerText="" id="c4">
            <af:outputText value="#{row.col1}" id="ot2"/>
          </af:column>
        </f:facet>

        <af:column sortable="false" headerText="Score" align="center" id="c5">
          <af:outputText value="#{row.col2}" id="ot6"/>
        </af:column>

        <af:column sortable="false" headerText="Verified by " align="center" id="c3">
          <af:outputText value="#{row.col3}" id="ot1"/>
        </af:column>
        <af:column sortable="false" headerText="On" align="center" id="c1">
          <af:outputText value="#{row.col4}" id="ot5"/>
        </af:column>
      </af:treeTable>

RowMaker.class

    public List row() {
            List<rowModel> ls = new ArrayList<rowModel>();

            for (int i = 0; i < 10; i++) {
                rowModel tr = new rowModel("+","92%","Person X","14 Feb 2013");
                ls.add(tr);
            }            
            return ls;
        }

RowModel.class

public class rowModel {

    String col1, col2, col3, col4;

    public rowModel(String col1, String col2, String col3, String col4) {
        this.col1 = col1;
        this.col2 = col2;
        this.col3 = col3;
        this.col4 = col4;
    }

    public String getCol1() {
        return col1;
    }
    public String getCol2() {
        return col2;
    }
    public String getCol3() {
        return col3;
    }
    public String getCol4() {
        return col4;
    }
}

Managed Bean

  <managed-bean id="__7">
    <managed-bean-name id="__5">MyBean</managed-bean-name>
    <managed-bean-class id="__8">com.im.popup.view.rowMaker</managed-bean-class>
    <managed-bean-scope id="__6">view</managed-bean-scope>
  </managed-bean>
Was it helpful?

Solution

The TreeTable would expect data of this form:

Manager1
 |-Employee1
 |-Employee2
Manager2
 |-Employee3
 |-Employee4

In your above example RowModel class doesn't have any children associated with it. I will take a very generic Employee example and show you how you can work with TreeTable:

class Employee{
  private String firstName;
  private String lastName;
  private List<Employee> directs;
  Employee(String fName, String lName){
    firstName = fName;
    lastName = lName;
    directs = new ArrayList<Employee>();
  }
  //Getters and setters for above
  public void addDirect(Employee emp){
    directs.add(emp);
  }
}

Lets look at creating the data for the TreeTable:

class TreeTablePageModel{
  List<Employee> managers = new ArrayList<Employee>();

  ChildPropertyTreeModel treeModel;
  public TreeTablePageModel(){
    Employee mgr1 = new Employee("First","Manager");
    Employee mgr2 = new Employee("Second","Manager");
    Employee mgr3 = new Employee("Third","Manager");

    Employee emp = new Employee("First","Sub_1");
    mgr1.addDirect(emp);
    emp = new Employee("First","Sub_2");
    mgr1.addDirect(emp);

    emp = new Employee("Second","Sub_1");
    mgr2.addDirect(emp);
    emp = new Employee("Second","Sub_2");
    mgr2.addDirect(emp);

    emp = new Employee("Third","Sub_1");
    mgr3.addDirect(emp);
    emp = new Employee("Third","Sub_2");
    mgr3.addDirect(emp);
    treeModel = new ChildPropertyTreeModel(managers,"directs");
  }

  public ChildPropertyTreeModel getTreeModel(){
    return treeModel;
  }
}

In the code above I am wrapping the List of my Employee objects into a ChildPropertyTreeModel and also passing it the name of the attribute using which the ADF component can obtain the values of its children. And in the JSP I would access the data as:

<af:treeTable rowBandingInterval="0" id="tt1" width="100%" value="#{viewScope.pageData.treeModel}">
<!-- add columns here -->
</af:treeTable>

And my managed bean declaration would be:

<managed-bean id="__7">
  <managed-bean-name id="__5">pageData</managed-bean-name>
  <managed-bean-class id="__8">com.im.popup.view.TreeTablePageModel</managed-bean-class>
  <managed-bean-scope id="__6">view</managed-bean-scope>
</managed-bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top