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

Luc Bors 1
0 0
Read Time:1 Minute, 32 Second

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.

About Post Author

Luc Bors

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).
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

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 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)

Comments are closed.

Next Post

My First Steps with RAC One Node 11gR2 (11.2.0.2)

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: