Skip to main content

A utility method to print the ViewCriteria returned by the search binding

A couple of years back I blogged about retrieving ViewCriteria(VC) from a custom queryListener method. This post in in continuation of the above said post. Recently while working on an example that deals with af:query component backed up by a VC, I noticed that it may also help developers to narrow down certain issues if they can print the ViewCrtieria returned by the search component. You can use the following code snippet in such scenarios. This may also help you to understand how framework construct ViewCriteria from af:query component. Here is the code snippet:

  //In managed bean - TestBean  
  //The customQueryListener(..) is the custom   
  //queryListener specified for the af:query  
  public void customQueryListener(QueryEvent queryEvent) {  
     //Read Query Descriptor  
     QueryDescriptor qd = queryEvent.getDescriptor();  
     DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();  
     /** The below call get ViewCriteria from the Search binding */  
     ViewCriteriaImpl vc = (ViewCriteriaImpl)getViewCriteria(bc, qd);  
     //Print VC   
     /** Manipulate ViewCriteria, if you want and  
      * then invoke query,optionally  
      * Note that, #{bindings.EmployeesViewCriteriaQuery.processQuery} is the serach   
      * binding EL generated by IDE when VC is dropped on to the page  
     invokeQueryEventMethodExpression("#{bindings.EmployeesViewCriteriaQuery.processQuery}", queryEvent);  

   //Prints VC  
   //This method will help you to   
   //understand how VC is created from the search binding(af:query)   

   public void printVC(ViewCriteria vc) {  
     List list = vc.getRows();  
     Iterator iter = list.iterator();  
     while (iter.hasNext()) {  
       ViewCriteriaRowImpl row = (ViewCriteriaRowImpl);  
       ViewCriteriaItem[] vcitems = row.getCriteriaItemArray();  
       for (ViewCriteriaItem vcitem : vcitems) {  
         if (vcitem != null) {  
           System.out.println("[ VC Item :" + vcitem.getColumnName() + " Value: " + vcitem.getValue() + " ]");  
           if (vcitem.getValueCount() > 1) {  
             ArrayList<ViewCriteriaItemValue> values = vcitem.getValues();  
             for (ViewCriteriaItemValue vcItemValue : values)  
               System.out.println(" [[ Multi select value :" + vcItemValue.getValue() + " ]]");  
           } else if ((vcitem.getValue()) instanceof ViewCriteria) {  
             System.out.println("<Nested VC is found...>");  
             //Call recursively   
    * Gets ViewCriteria used by the QueryModel  
   private ViewCriteria getViewCriteria(DCBindingContainer bc, QueryDescriptor qd) {  
     //EmployeesViewCriteriaQuery is the search binding name used in page def file  
     Object execBinding = bc.findExecutableBinding("EmployeesViewCriteriaQuery");  
     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 });  


You can download the sample workspace from here. [Runs with Oracle JDeveloper 11g R2 + Oracle XE]
To test this sample, run the test.jsf. You may notice that View Criteria used by the search component is getting printed in the server console window. The printVC(ViewCriteria vc) method in TestBean class will help you to understand how View Criteria is constructed for an af:query component at run time. You can also try modifying the code snippet given in the managed bean ( to alter the View Criteria  before passing it to business component layer for actual query execution.


Anonymous said…
Jobinesh, we need to refresh the LOV bind to the View criteria Item In Query. I see a method getAccessorVO(vo) , but for some reason its not working Iam not sure what the parameter vo is .. Do u have any ideas/suggestions..

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…