How-to tell the ViewCriteria a user chose in an af:query component
- by frank.nimphius
Normal
0
false
false
false
EN-US
X-NONE
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
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.
Normal
0
false
false
false
EN-US
X-NONE
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
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