Sunday, April 15, 2012

How to show/hide operators in adf:query advanced mode

In this post, I will provide a way to modify the operators list in the ADF query panel (af:query component) - i.e. to remove and add operators to the list. 
 (at the time of writing this post I didn't realise it was already documented here: http://docs.oracle.com/cd/E14571_01/web.1111/b31974/web_search_bc.htm#ADFFD2457)




The ADF Faces af:query component is a handy tool that neatly binds to an ADF bc View criteria defined in the model. 


In the default advanced mode, the query panel allows end users to select a suitable operator to apply to the query fields. The default list of these operators (of type JboCompOper) is populated based on the field's data type and ADF is rather intelligent with this feature - for example:
a) for an LOV based field, it displays an LOV if you select the Equals operator but changes to a text field when you choose the Starts-with operator...
b) It shows you two fields if you select the between operator. 


In my sample project based on the usual emp-dept schema, I have JobId as one of the search fields. In the advanced mode, by default, JobId is shown with the following default operators:


Sometimes you would want to hide some of these. The trick is to use the CompOper tag inside the View object's XML definition. 
The CompOper tag can be nested under either ViewAttribute or ViewCriteriaItem. 
So, to hide the Equals operator, you would use the following:
After adding some more tags under my JobId ViewAttribute, my operators list now looks like this:
Assumptions/Pre requisites:
The reader is familiar with what the Employee-Department schema is, basics of ADF like View object, view criteria etc. 


References:
The list of all possible fields is available here:
http://docs.oracle.com/cd/E15051_01/apirefs.1111/e10653/constant-values.html#oracle.jbo.common.JboCompOper