由于种种原因,一些开发人员不太接受使用ADF-BC作为业务服务层技术,他们还是倾向于使用Java类作为业务服务层的主要技术。
那么,如何使用POJO类绑定到ADF Table组件呢?
1. 定义模型类和Managed Bean
(1)模型类:Employee.java
package model.type;
public class Employee {
public Employee() {
super();
}
private String employeeName;
private String employeeNumber;
private String departmentNumber;
private String manager;
private String hireDate;
private String salary;
public Employee(String employeeNumber, String employeeName, String manager, String hireDate, String salary,
String departmentNumber) {
super();
this.employeeNumber = employeeNumber;
this.employeeName = employeeName;
this.departmentNumber = departmentNumber;
this.manager = manager;
this.hireDate = hireDate;
this.salary = salary;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeNumber(String employeeNumber) {
this.employeeNumber = employeeNumber;
}
public String getEmployeeNumber() {
return employeeNumber;
}
public void setDepartmentNumber(String departmentNumber) {
this.departmentNumber = departmentNumber;
}
public String getDepartmentNumber() {
return departmentNumber;
}
public void setManager(String manager) {
this.manager = manager;
}
public String getManager() {
return manager;
}
public void setHireDate(String hireDate) {
this.hireDate = hireDate;
}
public String getHireDate() {
return hireDate;
}
public void setSalary(String salary) {
this.salary = salary;
}
public String getSalary() {
return salary;
}
}
(2)Managed Bean类
package view;
import java.util.Arrays;
import java.util.List;
import model.type.Employee;
public class MyManagedBean {
public MyManagedBean() {
super();
}
private ListrowsData =
Arrays.asList(new Employee[] { new Employee("7369", "SMITH ", "7902", "12/17/1980", "800", "20"),
new Employee("7499", "ALLEN ", "7698", "2/20/1981", "1600", "30"),
new Employee("7521", "WARD ", "7698", "2/22/1981", "1250", "30"),
new Employee("7566", "JONES ", "7839", "4/2/1981", "2975", "20"),
new Employee("7654", "MARTIN ", "7698", "9/28/1981", "1250", "30"),
new Employee("7698", "BLAKE ", "7839", "5/1/1981", "2850", "30"),
new Employee("7782", "CLARK ", "7839", "6/9/1981", "2450", "10"),
new Employee("7788", "SCOTT ", "7566", "12/9/1982", "3000", "20"),
new Employee("7839", "KING ", "", "11/17/1981", "5000", "10"),
new Employee("7844", "TURNER ", "7698", "9/8/1981", "1500", "30"),
new Employee("7876", "ADAMS ", "7788", "1/12/1983", "1100", "20"),
new Employee("7900", "JAMES ", "7698", "12/3/1981", "950", "30"),
new Employee("7902", "FORD ", "7566", "12/3/1981", "3000", "20"),
new Employee("7934", "MILLER ", "7782", "1/23/1982", "1300", "10"),
new Employee("7469", "SMITHY ", "7902", "12/17/1980", "900", "20"),
new Employee("7599", "FALLEN ", "7698", "2/20/1981", "1700", "30"),
new Employee("7621", "WARDY ", "7698", "2/22/1981", "1350", "30"),
new Employee("7766", "BONES ", "7839", "4/2/1981", "2775", "20"),
new Employee("7754", "JUSTIN ", "7698", "9/28/1981", "1350", "30"),
new Employee("7798", "DRAKE ", "7839", "5/1/1981", "2650", "30"),
new Employee("7882", "MARK ", "7839", "6/9/1981", "2350", "10"),
new Employee("7888", "SCOTTY ", "7566", "12/9/1982", "3100", "20") });
public void setRowsData(ListrowsData) {
this.rowsData = rowsData;
}
public ListgetRowsData() {
return rowsData;
}
}
(3)在adfc-config.xml中注册该Managed Bean。
2. 绑定Managed Bean到ADF Table
(1)拖放ADF Table组件到页面
(2)拖放后会提示你选择绑定对象
(3)点击Create Managed Bean
(4)找到事先定义好的Managed Bean
(5)绑定到rowsData属性,这是一个集合对象。
(6)设置Element Type,指向Employee类,确定后,字段名称会自动匹配Employee类中的各个属性。
(7)设计时页面效果
3. 运行时页面效果
Project 下载:ADF_Table_POJO.7z
没有评论:
发表评论