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

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.
Image
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.
Image
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");
   vc.resetCriteria();
   VariableValueManager vvm = vc.ensureVariableManager();
   vvm.setVariableValue("globalSearchString", theString);
   vo.applyViewCriteria(vc,true);
}

Publish this method to the client so we can use it to search.
Image
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.
Image

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.
Image

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

Share.

About Author

Luc Bors is Expertise Lead ADF and technical specialist/architect at AMIS, Nieuwegein (The Netherlands). He developed several Workshops and training on ADF and also is an ADF and JHeadstart instructor. Luc is a member of the ADF Methodology group and publishes articles on ADF in oracle technology related magazines, on the AMIS technology blog, (http://technology.amis.nl/blog).

1 Comment

  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 criteria.so 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)