Tag Archives: QueryDescriptor

Getting the value of Saved search – programatic way


QueryModel qm = (QueryModel)evaluateEL("#{bindings.SearchViewCriteriaQuery.queryModel}");
 for(int indexCount=0; 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);
 System.out.println(isDefault);
 isRunAutomatically = (Boolean) m.get(QueryDescriptor.UIHINT_AUTO_EXECUTE);
 System.out.println(isRunAutomatically);
 if (Boolean.TRUE.equals(isDefault) && Boolean.TRUE.equals(isRunAutomatically){
 break();
 }
 else{
 queryDescriptorName = null;
 }
 System.out.println(isDefault);
 }

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.