Working with af:iterator and af:forEach programmatically (Populate values using POJO from Managed Bean)

Sharing is Caring

This is another post about Working programmatically with ADF (populating af:iterator and af:forEach programmatically )

Previously I have posted about populating af:iterator and af:forEach using ADF BC and binding layer to show the master-detail relation
Implementing master/detail tree relation using ADF Iterator and af:forEach for better UI designs – Oracle ADF

For this post, I am populating employee name and it’s department name using List data structure, to get and set the value of attributes

Created a java bean class, it has 2 variable for both attributes

public class EmployeeDet {
    public EmployeeDet(String name, String deptName) { = name;
        this.deptName = deptName;
    //Attribute to display EmployeeName and Department Name
    private String name;
    private String deptName;

public void setName(String name) { = name;

public String getName() {
return name;

public void setDeptName(String deptName) {
this.deptName = deptName;

public String getDeptName() {
return deptName;

Next step is to create a managed bean to populate data in af:iterator and af:forEach , this managed bean makes use of


java bean class to add data in the same format for all items of iterator and forEach. A List data structure is used to pass all values to the iterator. See code of managed bean

//Constructor-populate default records
public PopulateIteratorBean() {

EmployeeDet obj = new EmployeeDet("Ashish Awasthi", "Oracle ADF");
obj = new EmployeeDet("Alex Smith", "Java");
obj = new EmployeeDet("James S", "PHP");
//ArrayList to poplate data in af:iterator and af:forEach
private List<EmployeeDet> employeeDetail = new ArrayList();

public void setEmployeeDetail(List<EmployeeDet> employeeDetail) {
this.employeeDetail = employeeDetail;

public List<EmployeeDet> getEmployeeDetail() {

return employeeDetail;

Now drop af:iterator on the page and set its properties like value, var etc

using var reference of the iterator, set value in output text to show Employee Name and DepartmentName, see XML source of af:iterator

<af:panelGroupLayout id="pgl1" layout="horizontal">
                        <af:iterator id="i1" value="#{viewScope.PopulateIteratorBean.employeeDetail}" var="item">
                            <af:panelBox id="pb2" showDisclosure="false">
                                <f:facet name="toolbar"/>
                                <af:panelGroupLayout id="pgl3" layout="horizontal">
                                    <af:outputText value="#{}" id="ot1"
                                                   inlineStyle="font-weight:bold; font-size:medium; color:#0572ce;;"/>
                                    <af:spacer width="2" height="0" id="s1"/>
                                    <af:outputText value="(#{item.deptName})" id="ot2"

on running it looks like this-



Now I am doing the same for af:forEach

<af:panelGroupLayout id="pgl2" layout="horizontal">
                        <af:forEach items="#{viewScope.PopulateIteratorBean.employeeDetail}" var="feach">
                            <af:showDetailHeader text="#{feach.deptName}" disclosed="true" id="sdh1">
                                <af:outputText value="#{}" id="ot3"
                                               inlineStyle="font-weight:bold; font-size:medium; color:#0572ce;;"/>

on running it looks like this, Isn’t it look good 😉

Sample ADF Application-Download
Thanks, Happy Learning 🙂

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “Working with af:iterator and af:forEach programmatically (Populate values using POJO from Managed Bean)”

  1. Hi,
    nice post, and nice blog. I have a question, what if i want to let data flow on second line, then third line….etc, like the view in merchandising websites. I am stuck in this, so your answer will help me a lot.

  2. Hi,
    Thanks very much for publishing this! Would you know if and can not be used within ? I've tried both using ADF, and neither seems to work.

    I appreciate any help you offer.

Leave a Reply

Your email address will not be published. Required fields are marked *