Adf table can be wired with java ArrayList.Default sorting is automatically enabled for this.
Use Case: Bind java List type of Collection with ADF table for CRUD operations.It is not always possible to use ADF BC as a service.In that scenario we can use ADF faces as a normal JSF library and take the advantages of ADF faces great features like sorting,filtering row selection etc.
Implementation:
1. Data transfer Object(DTO) class for holding the data: EmployeeDTO
public class EmployeeDTO {
private int id;
private String name;
private String dept;
public EmployeeDTO() {
super();
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getDept() {
return dept;
}
}
2.Managed bean Code:
public class BlogMBean {
private List<EmployeeDTO> empTable=new ArrayList<EmployeeDTO>();
public BlogMBean() {
EmployeeDTO dto=new EmployeeDTO();
dto.setId(100);
dto.setName("A");
dto.setDept("IT");
EmployeeDTO dto2=new EmployeeDTO();
dto2.setId(101);
dto2.setName("B");
dto2.setDept("CS");
EmployeeDTO dto3=new EmployeeDTO();
dto3.setId(102);
dto3.setName("C");
dto3.setDept("LS");
empTable.add(dto);
empTable.add(dto2);
empTable.add(dto3);
}
public void setEmpTable(List<EmployeeDTO> empTable) {
this.empTable = empTable;
}
public List<EmployeeDTO> getEmpTable() {
return empTable;
}
}
3. UI code: jspx
<af:panelGroupLayout id="pgl1" layout="vertical">
<af:panelCollection id="pc1" styleClass="AFStretchWidth">
<f:facet name="menus"/>
<f:facet name="toolbar"/>
<f:facet name="statusbar"/>
<af:table var="row" rowBandingInterval="0" id="t1"
rowSelection="single"
value="#{viewScope.BlogMBean.empTable}">
<af:column sortable="true" filterable="true" headerText="Id" sortProperty="id" >
<af:outputText value="#{row.id}"/>
</af:column>
<af:column sortable="true" filterable="true" headerText="Name" sortProperty="name" >
<af:outputText value="#{row.name}" />
</af:column>
<af:column sortable="true" filterable="true" headerText="Department" sortProperty="dept" >
<af:outputText value="#{row.dept}"/>
</af:column>
</af:table>
</af:panelCollection>
</af:panelGroupLayout>
Use Case: Bind java List type of Collection with ADF table for CRUD operations.It is not always possible to use ADF BC as a service.In that scenario we can use ADF faces as a normal JSF library and take the advantages of ADF faces great features like sorting,filtering row selection etc.
Implementation:
1. Data transfer Object(DTO) class for holding the data: EmployeeDTO
public class EmployeeDTO {
private int id;
private String name;
private String dept;
public EmployeeDTO() {
super();
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getDept() {
return dept;
}
}
2.Managed bean Code:
public class BlogMBean {
private List<EmployeeDTO> empTable=new ArrayList<EmployeeDTO>();
public BlogMBean() {
EmployeeDTO dto=new EmployeeDTO();
dto.setId(100);
dto.setName("A");
dto.setDept("IT");
EmployeeDTO dto2=new EmployeeDTO();
dto2.setId(101);
dto2.setName("B");
dto2.setDept("CS");
EmployeeDTO dto3=new EmployeeDTO();
dto3.setId(102);
dto3.setName("C");
dto3.setDept("LS");
empTable.add(dto);
empTable.add(dto2);
empTable.add(dto3);
}
public void setEmpTable(List<EmployeeDTO> empTable) {
this.empTable = empTable;
}
public List<EmployeeDTO> getEmpTable() {
return empTable;
}
}
3. UI code: jspx
<af:panelGroupLayout id="pgl1" layout="vertical">
<af:panelCollection id="pc1" styleClass="AFStretchWidth">
<f:facet name="menus"/>
<f:facet name="toolbar"/>
<f:facet name="statusbar"/>
<af:table var="row" rowBandingInterval="0" id="t1"
rowSelection="single"
value="#{viewScope.BlogMBean.empTable}">
<af:column sortable="true" filterable="true" headerText="Id" sortProperty="id" >
<af:outputText value="#{row.id}"/>
</af:column>
<af:column sortable="true" filterable="true" headerText="Name" sortProperty="name" >
<af:outputText value="#{row.name}" />
</af:column>
<af:column sortable="true" filterable="true" headerText="Department" sortProperty="dept" >
<af:outputText value="#{row.dept}"/>
</af:column>
</af:table>
</af:panelCollection>
</af:panelGroupLayout>
4. Running Example:
No comments:
Post a Comment