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

6 comments:

Unknown said...

thanks for this post! i wanted some info about the CompOper tag which i saw being used somewhere, to confirm whether it really does what i thought it does, and your post confirms that it does :)

Anonymous said...

Hi Jang,
I want to hide
* Less than
* Less than or equal to
* Between
* Not between
from advance search options drop down list. Once I use "<" in Oper it says not allowed in this attribute. What are the symbols I should use for "Less than" & "Between" in "Oper" attribute

Regards !
Sameera

Jang Vijay Singh said...

For the 'less than or equal to' operator,
use
Oper=" & lt ; = " (without any space)

e.g.


(without any space)
The 'Oper' names for all these operators are listed here:
http://docs.oracle.com/cd/E15051_01/apirefs.1111/e10653/constant-values.html#oracle.jbo.common.JboCompOper

(Search for JboCompOper on that page to find the list)

Anonymous said...

Hi Jang,
Got it. Thanks for the helping hand.

Regards !
Sameera

Benjamin said...

Hi Jang, Thanks for your post.
I didn't know that we could customize the operators on the ViewAttribute.

I've just tried it works well, but the views in our portal are in SQL Mode Expert, and when I edit the Query and click OK with no modification, all the customizations are lost. (I think the tool rebuilt all the ViewAttribute).
If customizations have been done on ViewCriteriaItem it's ok, but in our case, the attributs queriables are not necessarily present on the viewCriteria, so we can't use this option (I think)

Do you have any suggestion ?
Thanks in advance

Benjamin

Sameera Samarasinghe said...

Hi Jang,
I want to hide
* Does not equal
from advance search options drop down list. I tried with "<>" which is given in the doc you mentioned. But it says "<" in Oper it says not allowed in this attribute. Please give me a helping hand

Regards !
Sameera