How To Build a Simple UIX Search Form

An Oracle JDeveloper How To Document
Written by Shay Shmeltzer, Oracle Corporation
July, 2004

Introduction

One of the common tasks developers are looking to create is search forms that will allow them to query the database according to specific conditions. This sample uses Oracle ADF Business Components, Struts, and UIX to show the basic steps to building such a form. This document will show you how to use the powerful setWhereClause method of ADF BC View objects and combine it with a simple Struts flow.

Creating the Data Model and Exposing a Client Method

Create a new ADF Business Component based on the HR Employees table. Make sure you create an entity(Employees), a view object (EmployeesView), and an application module (which includes at least the EmployeesView1).

Now we'll create a method that will set the Where clause of the base query for the View object.
Click on the application module, in the structure pane double click the java file that implements the appmodule to open its Java source file in the editor.


Add a new method to this file as follows:

  public void setCondition (String p_cond)
  {    
    ViewObject empvo = findViewObject("EmployeesView1");
        //Creating a Where clause for the query
    String whereclause = "LAST_NAME like '%"+ p_cond +"%'";
    empvo.setWhereClause(whereclause);
    empvo.executeQuery();
  }

Note: A better way to do this type of parameter-based where clause is to use bind variables in the view object where clause. Using bind variables results in better performance. Here is an example of using bind variables.

Tip: The name of the view object - "EmployeesView1" in this case - is defined in the data model of the application module - it is not the generic view object name.

Now we need to expose this method to clients of the application module. To do this, double click the application module to open the edit dialog.
In the client interface node shuttle the new method you created to the right to expose it to developers and click ok.


Creating the Controller and View Layers

Now that our Model layer is set, lets build the UIX view layer and the Struts controller.

Open the Struts diagram and create a new datapage. Double click the page and choose datapage1.uix from the list to open the UIX visual editor.
From the data component palette drag and drop the EmployeeView as a read only table onto the UIX page.

Back in the struts page-flow modeler add a new Data Action to the diagram, name it setCondition.
In the Data Component palette expand the Operations node. The setCondition method that we exposed before is visible here. Drag and drop the setCondition method onto the Action in the diagram.
Create a Forward link from the action back to the data page. This Forward link needs to be called success - and this will be the default in this case.

Go back to the UIX page visual editor. From the component palette choose the ADF UIX Components. Drag and Drop a textInput above the UIX table.
In the property inspector change the name of the textInput to ename.

Add a submitButton from the component palette to the UIX page just after the textInput.
Set the text property of the submitButton to Query. Set the event property to query.


Now we need to create the UIX event handler. When you cursor is positioned on the event name property in the property palette, you'll see a link that will take you to the event ("go to event handler"). Click on it to create the event.

Navigate to the event in the structure pane, right click on the event to choose Insert Inside Event- Query -> UIX Servlet -> go. In the dialog that pops-up name the destination query and click ok.

Back in the Struts Page Flow add a forward link from the datapage to the setCondition action and rename it to query.

Now we need to indicate to the setCondition action to use the value of the field as a parameter to the method.

Back in the Struts Diagram - go to the structure window and expand it to locate the setCondition node under the Action Mappings. Expand this node and set the paramNames[0] property to ${param.ename}

Right click on the datapage and choose run. in the HTML page that comes up you can insert conditions that will limit the employees that are retrieved by their last name.

You can get a JDeveloper project with the source code for this example here.

false ,,,,,,,,,,,,,,,