Getting the value of Saved search in programatic way


This code can be added to the setter of the component from where you want to access the saved search of the af:query panel

QueryModel qm = (QueryModel)evaluateEL("#{bindings.<searchRegionFromThePageDef>.queryModel}");
for(int indexCount=0; indexCount<qm.getUserQueries().size();indexCount++)
{
 QueryDescriptor qd = qm.getUserQueries().get(indexCount);
 if(qd!=null){
 String queryDescriptorName = qd.getName();
 System.out.println(queryDesctiptorName);
 m = qd.getUIHints();
 isDefault = (Boolean) m.get(QueryDescriptor.UIHINT_DEFAULT);
 isRunAutomatically = (Boolean) m.get(QueryDescriptor.UIHINT_AUTO_EXECUTE);

 if (Boolean.TRUE.equals(isDefault) && Boolean.TRUE.equals(isRunAutomatically){
 //code goes here
 }
 else{
 //else code
 }
 }
}

quick walk through..

  • Getting the handle to QueryModel
  • Iterating through the userQueries. ie. the Saved Searches
  • Get handle to the QueryDescriptor
  • get handle to UIHints from the QueryDescriptor
  • check for QueryDescriptor.UIHINT_DEFAULT and QueryDescriptor.UIHINT_AUTO_EXECUTE and implement the logic based on the value obtained.
Advertisements

One thought on “Getting the value of Saved search in programatic way

  1. Darshan Kumar

    Hi, is there a way to enable site level Saved Search.
    for ex: In a company if there are 10 users say user_1 , user_2, user_3, now if user_1 creates a saved search, that particular saved search should be seen by all other users i.e. user_2, user_3 .

    Is there a way to achieve this ?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s