In Oracle ADF, search form can be created with BC4J/EJB model using "View Criteria/Named Criteria" by dropping "af:query" component in view layer. Here in this article, I'm trying to build simple search form based on bean data control.
The Results page look like below.
Enter the Department Id in search form and click search button will filter results.
You can download the sample workspace from here
[Runs with Oracle JDeveloper 11.1.2.0.0 (11g R2) + HR Schema]
Implementation Steps
Create Fusion Web application, in model project create Employees java class. Open Employees.java and add the below code.
The Results page look like below.
Enter the Department Id in search form and click search button will filter results.
You can download the sample workspace from here
[Runs with Oracle JDeveloper 11.1.2.0.0 (11g R2) + HR Schema]
Implementation Steps
Create Fusion Web application, in model project create Employees java class. Open Employees.java and add the below code.
public class Employees {
private Integer employeeId;
private String firstName;
private String lastName;
private String email;
private String phoneNo;
private Date hireDate;
private String jobId;
private Integer salary;
private Integer departmentId;
public Employees() {
super();
}
public Employees(int employeeId, String firstName, String lastName, String email, String phoneNo, Date hireDate,
String jobId, int salary, int departmentId) {
this.setEmployeeId(employeeId);
this.setFirstName(firstName);
this.setLastName(lastName);
this.setEmail(email);
this.setPhoneNo(phoneNo);
this.setHireDate(hireDate);
this.setJobId(jobId);
this.setSalary(salary);
this.setDepartmentId(departmentId);
}
public void setEmployeeId(Integer employeeId) {
this.employeeId = employeeId;
}
public Integer getEmployeeId() {
return employeeId;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return lastName;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getPhoneNo() {
return phoneNo;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
public Date getHireDate() {
return hireDate;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getJobId() {
return jobId;
}
public void setSalary(Integer salary) {
this.salary = salary;
}
public Integer getSalary() {
return salary;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public Integer getDepartmentId() {
return departmentId;
}
}
Create PopulateData java class, open PopulateData.java and add the below code.public class PopulateData {
private static List allEmployees;
static {
allEmployees = new ArrayList();
allEmployees.add(new Employees(100, "Steven", "King", "SKING", "515.123.4567", new Date(), "AD_PRES", 24000,
20));
allEmployees.add(new Employees(101, "Neena ", "Kochhar", "NKOCHHAR", "515.123.4568", new Date(), "AD_VP",
17000, 90));
allEmployees.add(new Employees(102, "Lex", "De Haan", "AHUNOLD", "515.423.4567", new Date(), "IT_PROG", 15000,
90));
allEmployees.add(new Employees(103, "Alexander", "Hunold", "AHUNOLD", "515.423.4567", new Date(), "IT_PROG",
10000, 20));
allEmployees.add(new Employees(104, "Bruce", "Ernst", "BERNST", "515.423.4568", new Date(), "IT_PROG", 5000,
50));
allEmployees.add(new Employees(105, "David", "Austin", "DAUSTIN", "515.423.4569", new Date(), "IT_PROG", 7000,
30));
allEmployees.add(new Employees(106, "Valli", "Pataballa", "VPATABAL", "515.423.4560", new Date(), "IT_PROG",
8000, 50));
allEmployees.add(new Employees(107, "Diana", "Lorentz", "DLORENTZ", "515.423.5567", new Date(), "IT_PROG",
9000, 50));
allEmployees.add(new Employees(108, "Nancy", "Greenberg", "NGREENBE", "515.124.4569", new Date(), "FI_MGR",
10000, 100));
allEmployees.add(new Employees(109, "Daniel", "Faviet", "DFAVIET", "515.124.4169", new Date(), "FI_ACCOUNT",
13000, 100));
allEmployees.add(new Employees(110, "John", "Chen", "JCHEN", "515.124.4269", new Date(), "FI_ACCOUNT", 14000,
100));
allEmployees.add(new Employees(111, "Ismael", "Sciarra", "ISCIARRA", "515.124.4369 ", new Date(), "FI_ACCOUNT",
12000, 60));
allEmployees.add(new Employees(112, "Jose Manuel", "Urman", "JMURMAN", "515.124.4469", new Date(),
"FI_ACCOUNT", 4000, 60));
allEmployees.add(new Employees(112, "Jose Manuel", "Urman", "JMURMAN", "515.124.4469", new Date(),
"FI_ACCOUNT", 7800, 60));
allEmployees.add(new Employees(113, "Luis", "Popp", "LPOPP", "515.124.4567", new Date(), "FI_ACCOUNT", 6900,
70));
allEmployees.add(new Employees(114, "Den", "Raphaely", "DRAPHEAL", "515.127.4561", new Date(), "PU_MAN", 11000,
90));
}
public PopulateData() {
super();
}
public static List getAllEmployees() {
return allEmployees;
}
}
Create EmployeeServicejava class, open EmployeeService.java and add the below code. Create data control from EmployeeService Bean class.public List filterByDeptId(Integer departmentId) {
try {
List allEmployees = PopulateData.getAllEmployees();
if (departmentId != null) {
List filteredEmployees = new ArrayList();
for (Employees e : allEmployees) {
if (e.getDepartmentId() == departmentId) {
filteredEmployees.add(e);
}
}
return filteredEmployees;
} else {
return allEmployees;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public List getAllEmployees() {
return PopulateData.getAllEmployees();
}
In ViewController project, create jspx page and from data control palette- Drop filterByDeptId as ADF Method Parameter
- Drop filterByDeptId->Employees->Table as ADF Read-only Table