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

Luc Bors 1

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 thought on “ADF 11g : Implementing Search for Multiple Attributes of a View Object

  1. Hi,

        thanks for the nice post.
        i have a table called codes(code,text)
       ex data:
        code      text
        school    st.joseph
        school    edward high school
        flowers    rose
       flowers     lilly
       fruits         apple
       fruits         custord apple
       i have a several fields in jsf page where i want 
    lov based on above table codes
    for ex for field one i wanted to display fruits list
    for field one i wanted to display flowers list etc
    so i created view object for codes and applied view for each field i have to create one instance of viewobject.
    can you please suggest us the best way to to do this?
       Based on this , i created a viewobject with db table called codes(code,text)

Comments are closed.

Next Post

My First Steps with RAC One Node 11gR2 (

I’ve been using RAC (10gR2) for years now and I was wondering how RAC One Node differs from RAC. That’s why I used a few ‘old’ RAC servers that we had ‘laying’ around to install a RAC One Node Cluster. I also used that cluster to get some hands on […]
%d bloggers like this: