How To Build a Simple JSP Search Form

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


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 JSP 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 +"%'";

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 JSP view layer and the Struts controller.

Open the Struts diagram and create a new datapage. Double click the page to edit the JSP editor.
From the data component palette drag and drop the EmployeeView as a read only table onto the JSP 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.

Now we'll add to the datapage a Struts form that will allow us to insert our query condition.

Go back to the JSP page visual editor. From the component palette choose the Struts HTML components. Drag and Drop a Form to the end of the JSP page.
In the dialog that pops up select the action from the list for the action property.

Switch the component palette to HTML and add a Text Field inside the Struts Form you have just created.
Set the name property of the text field to ename.
Add a Submit Button to the Struts form from the component palette (you can change its value property 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 Struts diagram and choose Diagram->refresh diagram from all pages.. A new link will show you that the datapage is calling the data action.

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.

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