Friday 30 November 2012

Populate ADF table from Managed Bean

To create a ADF table and populate it from backing bean, define a List in backing bean and populate it with table data. Also the EL #{row.col1} won't work since String.getCol1() does not exists. So define a pojo class to populate the row values. In below example, its Employee.


In adf page :


<af:table var="row" rowBandingInterval="0" id="t1"
                      value="#{pageFlowScope.SampleManagedBean.empList}">
              <af:column sortable="false" headerText="EmpId" id="c1">
                <af:outputText value="#{row.empid}" id="ot2"/>
              </af:column>
              <af:column sortable="false" headerText="EmpName" id="c2">
                <af:outputText value="#{row.empname}" id="ot1"/>
              </af:column>
</af:table>


In managed bean:


public class SampleManagedBean {
    private List<Employee> empList;

    public SampleManagedBean() {
        super();
    }

    public void populateList() {
        empList=new ArrayList();
        empList.add(new Employee(1, "Emp1"));
        empList.add(new Employee(2, "Emp2"));
        empList.add(new Employee(3, "Emp3"));
    }

    public void setEmpList(List<Employee> empList) {
        this.empList = empList;
    }

    public List<Employee> getEmpList() {
        if(empList==null)
        this.populateList();
        return empList;
    }
}

In Employee class :

public class Employee {
    private int empid;
    private String empname;
    public Employee(int id,String name) {
       this.empid=id;
       this.empname=name;
    }

    public void setEmpid(int empid) {
        this.empid = empid;
    }

    public int getEmpid() {
        return empid;
    }

    public void setEmpname(String empname) {
        this.empname = empname;
    }

    public String getEmpname() {
        return empname;
    }
}

You can download the SampleApp here

Tuesday 27 November 2012

Invoke ADF bindings in page templates

In order to access method binding in page template pagedef , get its reference in consumer pagedef executable section. We can use standard ADFUtil for this. Find the attached ADFUtil here

In DataBindings.cpx file, we can find the pagetemplate pagedef id.


Executable section of consumer pagedef :

    public void getEmployeeRecord() {       
        //access page template Pagedef reference in executable section of consumer page PageDef
        DCBindingContainer binding =
           (DCBindingContainer)ADFUtil.evaluateEL("#{bindings.data.portal_pageTemplate_globePageDef}");
      
        //get the MethodBinding
        OperationBinding operationbinding = (OperationBinding)binding.get("getEmployeeNames");
       
        //invoke the method
        if (operationbinding != null)
            operationbinding.execute();
    }