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"   
        <f:facet name="end">  
          <af:commandLink text="Advanced"/>  

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 =   
  /** The below call get ViewCriteria from the Search binding */  
  ViewCriteria vc = getViewCriteria(bc, qd);   
  /** Manipulate ViewCriteria, if you want and 
   *  then invoke query,optionally 
   * Gets ViewCriteria used by the QueryModel
  private ViewCriteria getViewCriteria(DCBindingContainer bc,   
            QueryDescriptor qd) {   
   Object execBinding =   
  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 =   
  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-


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

Popular posts from this blog

Happy New Year 2018 !

We can't go back and change the beginning, but we always can start where we are and change the ending. Believe in yourself and you will be unstoppable!

Wishing you and your family a very happy new year 2018 !!!

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…