Thursday, July 12, 2012

Bean Data Control - Create Simple Search Form

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 (11g R2) + HR Schema]

Implementation Steps

Create Fusion Web application, in model project create Employees java class. Open 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() {

    public Employees(int employeeId, String firstName, String lastName, String email, String phoneNo, Date hireDate,
                     String jobId, int salary, int 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) { = 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 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,
        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,
        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,
        allEmployees.add(new Employees(105, "David", "Austin", "DAUSTIN", "515.423.4569", new Date(), "IT_PROG", 7000,
        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,
        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,
        allEmployees.add(new Employees(114, "Den", "Raphaely", "DRAPHEAL", "515.127.4561", new Date(), "PU_MAN", 11000,

    public PopulateData() {

    public static List getAllEmployees() {
        return allEmployees;
Create EmployeeServicejava class, open 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) {
                return filteredEmployees;
            } else {
                return allEmployees;
        } catch (Exception e) {
        return null;

public List getAllEmployees() {
    return PopulateData.getAllEmployees();
In ViewController project, create jspx page and from data control palette
  1. Drop filterByDeptId as ADF Method Parameter
  2. Drop filterByDeptId->Employees->Table as ADF Read-only Table


  1. Hi Deepak.How are you?i am using Jdev if i am not creating any data control out of session bean?i have another pojo class based on session bean where i need to create the Datacontrol. In that case i am not gonna get all the facility which session bean datacontrol give(Eg:NamedQuery),and in that case how to make a custom search page with some custom value ,i will appreciate your feedback Deepak,


    1. Hi Satya,

      @NamedQuery - is a JPA feature which supported on JPA Entities only.
      Named Criteria - Only DataControls that implement FilterableDataControl has criteria support.

      So we have implement our own methods to filter the data sets to display in custom search page

      - Deepak