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 master-detail relation
Implementing master/detail tree relation using af: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 datastructure ,to get and set value of attributes
Created a
java bean class , it has 2 variable for both attributes
public class EmployeeDet {
public EmployeeDet(String name, String deptName) {
this.name = name;
this.deptName = deptName;
}
//Attribute to display EmployeeName and Department Name
private String name;
private String deptName;
public void setName(String name) {
this.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
EmployeeDet
java bean class to add data in same
format for all items of iterator and forEach. A List data structure is used to pass all
values to iterator. See code of managed bean
//Constructor-populate default records
public PopulateIteratorBean() {
EmployeeDet obj = new EmployeeDet("Ashish Awasthi", "Oracle ADF");
employeeDetail.add(obj);
obj = new EmployeeDet("Alex Smith", "Java");
employeeDetail.add(obj);
obj = new EmployeeDet("James S", "PHP");
employeeDetail.add(obj);
}
//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 page and set it's properties like
value, var etc
using
var reference of
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="#{item.name}" 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"
inlineStyle="font-weight:bold;font-size:small;color:red;"/>
</af:panelGroupLayout>
</af:panelBox>
</af:iterator>
</af:panelGroupLayout>
on running it looks like this-
do 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="#{feach.name}" id="ot3"
inlineStyle="font-weight:bold; font-size:medium; color:#0572ce;;"/>
</af:showDetailHeader>
</af:forEach>
</af:panelGroupLayout>
on running it looks like this-
Sample ADF Application-
Download
Thanks, Happy Learning :)