How-to tell the ViewCriteria a user chose in an af:query component

The af:query component defines a search form for application users to enter search conditions for a selected View Criteria. A View Criteria is a named where clauses that you can create declaratively on the ADF Business Component View Object.

A default View Criteria that allows users to search in all attributes exists by default and exposed in the Data Controls panel.

To create an ADF Faces search form, expand the View Object node that contains the View Criteria definition in the Data Controls panel. Drag the View Criteria that should be displayed as the default criteria onto the page and choose Query in the opened context menu. One of the options within the Query option is to create an ADF Query Panel with Table, which displays the result set in a table view, which can have additional column filters defined.

To intercept the user query for modification, or just to know about the selected View Criteria, you override the QueryListener property on the af:query component of the af:table component. Overriding the QueryListener on the table makes sense if the table allows users to further filter the result set using column filters.

To override the default QueryListener, copy the existing string referencing the binding layer to the clipboard and then select Edit from the field context menu (press the arrow icon to open it) to selecte or create a new managed bean and method to handle the query event.

 The code below is from a managed bean with custom query listener handlers defined for the af:query component and the af:table component. The default listener entry copied to the clipboard was "#{bindings.ImplicitViewCriteriaQuery.processQuery}"

 public void onQueryList(QueryEvent queryEvent) {
  // The generated QueryListener replaced by this method
  //#{bindings.ImplicitViewCriteriaQuery.processQuery}     
  QueryDescriptor qdes = queryEvent.getDescriptor();     
 
  //print or log selected View Criteria
  System.out.println("NAME "+qdes.getName());

       
  //call default Query Event     
  invokeQueryEventMethodExpression("
     #{bindings.ImplicitViewCriteriaQuery.processQuery}",queryEvent);

 }

public void onQueryTable(QueryEvent queryEvent) {
  // The generated QueryListener replaced by this method
  //#{bindings.ImplicitViewCriteriaQuery.processQuery}
  QueryDescriptor qdes = queryEvent.getDescriptor();

  //print or log selected View Criteria
  System.out.println("NAME "+qdes.getName());     
          
  invokeQueryEventMethodExpression(
    "#{bindings.ImplicitViewCriteriaQuery.processQuery}",queryEvent);
}

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

Of course, this code also can be used as a starting point for other query manipulations and also works with saved custom criterias.

To read more about the af:query component, see:

http://download.oracle.com/docs/cd/E15523_01/apirefs.1111/e12419/tagdoc/af_query.html

Comments:

Post a Comment:
Comments are closed for this entry.
About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today