ADF 11g : Implementing Search for Multiple Attributes of a View Object

Today I was asked to build a search component that searches a view object for all occurrences of a search string entered by the user. It should look like the ADF Quick Query Component, however, without choice for the attributes to search on. All attributes are search-able. I choose to combine ViewCriteria and custom method on the Application Module. Here is how I did it.

I started with the creation of Default Business Components for the Employees table. Next I created a Bindvariable to represent the value entered by the user.
After that I created view Criteria containing ‘OR’ conjunctions and ‘CONTAINS’ clauses for all attributes that I need to search on. The image below depicts what the view criteria look like.
Final part in the ADF-BC project is to create a custom method on the Application Module to apply view criteria to the view object and to apply the user entered value to the bind variable.

public void applyVCforGlobalSearchEmployees(String theString){
   ViewObjectImpl vo = getEmployeesView1();
   ViewCriteria vc = vo.getViewCriteria("EmployeesViewCriteria");
   VariableValueManager vvm = vc.ensureVariableManager();
   vvm.setVariableValue("globalSearchString", theString);

Publish this method to the client so we can use it to search.
The published method is now ready to be used on the page (assuming you created one). If not, just create a simple page containing a table based on the employees collection. Drop the method as an ADF Parameter form.

If all is ok, JDeveloper will take care of the partial triggering to refresh the table after the button has been pressed. For the looks, I added a custom icon to the button,adjusted the labels and prompts and moved to component to a toolbar facet.

Here you go. Searching for multiple fields in a viewObject. Download the sample workspace here.

One Response

  1. Murali September 29, 2011