Skip to main content

Retrieving ViewCriteria from a custom queryListener method

You can leverage the built in functionalities of <af:quickQuery> or <af:query> component to build search functionalities for your screen. Sometimes you may need to intercept the query invocation using queryListener of the query component as shown below.

  <af:quickQuery label="Search" id="search"   
               value="#{bean.queryDescriptor}"   
               queryListener="#{someBean.processSomeQuery}">  
        <f:facet name="end">  
          <af:commandLink text="Advanced"/>  
        </f:facet>  
  </af:quickQuery>  

In today's post I'm sharing some code snippets which may help you to retrieve model part of the </af:quickQuery> component.

   
 public void processSomeQuery(QueryEvent queryEvent) {   
     
  QueryDescriptor qd = queryEvent.getDescriptor();   
  AttributeCriterion criterion = qd.getCurrentCriterion();  
 
  /** Gets the currently keyed in search criteria for quickQuery,
   *  You can do manipulate the values here :)
   */
  String attrLabel = criterion.getAttribute().getLabel();   
  Object attrValue = criterion.getValues().get(0);   

  DCBindingContainer bc =   
  (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();   
    
  /** The below call get ViewCriteria from the Search binding */  
  ViewCriteria vc = getViewCriteria(bc, qd);   
   
  /** Manipulate ViewCriteria, if you want and 
   *  then invoke query,optionally 
   */   
  invokeQueryEventMethodExpression("#{bindings.ImplicitViewCriteriaQuery.processQuery}",   
         queryEvent);   
  }   
  /**
   * Gets ViewCriteria used by the QueryModel
   */     
  private ViewCriteria getViewCriteria(DCBindingContainer bc,   
            QueryDescriptor qd) {   
              
   Object execBinding =   
     bc.findExecutableBinding("ImplicitViewCriteriaQuery");   
  ViewCriteria vc =   
   JUSearchBindingCustomizer.getViewCriteria((DCBindingContainer)execBinding, qd.getName());   
  return vc;   
    
  }   
      
  private void invokeQueryEventMethodExpression(String expression,   
               QueryEvent queryEvent) {   
                 
  FacesContext fctx = FacesContext.getCurrentInstance();   
  ELContext elctx = fctx.getELContext();   
  ExpressionFactory efactory =   
   fctx.getApplication().getExpressionFactory();   
  MethodExpression me =   
   efactory.createMethodExpression(elctx, expression, Object.class,   
             new Class[] { QueryEvent.class });   
  me.invoke(elctx, new Object[] { queryEvent });   
    
  }   



Learn More ...

There are a lot more points like this. If  you are curious to learn the internals of the ADF Business Components and ADF Binding Layer,  the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html

Comments

Hasim said…
If i want to revrieve multiple selected value from viewcriteria in multi select check box then how do i do. I am just gettin gone value.
Erik Piché said…
Thanks, very handy! :-)
Don Kleppinger said…
The invokeQueryEventMethodExpression method does not appear to work if the table is based on a POJO data control. Has to retrieve search binding and cast to internal oracle class to get it to work. ((FacesCtrlSearchBinding) execBinding).processQuery(queryEvent);
see
https://community.oracle.com/message/12910014#12910014

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…