Friday, November 20, 2009

Displaying pre-executed query result in a search form

I recently encountered an interesting use case related to Search Binding. Requirement is to display the result of pre executed query in a search form embedded inside a popup dialog. Developer tried executing the query from popupFetchListener, but no success in displaying the search result back on the form. Always search result component comes empty. What has gone wrong here?

Before start seeing the implementation part, let us try to understand the model driven query component's runtime behavior. <af:query> component's binding(search binding) by default, follow 'AutoQuery-or-ClearRowSet' behavior. In simple words, search binding for <af:query> component will try to perform either of the below steps(AutoQuery or ClearRowSet) while rendering the page where the component is embedded.

AutoQuery : <af:query> component follows model driven rendering approach. Obviously the ViewCriteria defined in the ViewObject, decides query component's runtime behavior. If the ViewCriteria has Query Automatically flag set to true, then runtime will apply the ViewCriteria and execute query when <af:query> component is being rendered. And the search results will be displayed in the specified component.

ClearRowSet : If the AutoQuery is not performed (i.e Query Automatically flag is set false for the ViewCriteria), then search binding clears the row set related to its iterator. User will be presented with empty search results component.

More details on this topic can be found in Fusion Developer's Guide for Oracle Application Development Framework 27 Creating ADF Databound Search Forms

Now, let us go back to the use case that we were discussing initially, it is clear that we need to override 'AutoQuery-or-ClearRowSet' behaviour of the search binding in order to display the result of the pre executed query. Good news is that, ADF binding layer has support for this kind of use case scenario 'out of the box'. A search binding's InitialQueryOverridden property controls whether it should suppress its initial AutoQuery-or-ClearRowSet behavior the first time the search binding is used in a page flow. If InitialQueryOverridden is true, then all valid values, including true, false, or a boolean-valued EL expression, are suppressed. The default value is false. So keeping this flag ‘true’ is enough to achieve the above mentioned use case. This property can be located in your page definition file, inside < searchRegion >.


Please go through Fusion Developer's Guide Chapter 27.2.4 How to Set Default Search Binding Behavior to know more.

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS1 + HR Schema]

3 comments:

Anonymous said...

Hi,
Thanks for the post.
Can we know where this pre-executed query fires. is this in some default method activity?

How do you achieve the same by making it a part of the af:query.

thanks.

Jobinesh said...

You can keep this as default method activity as well, again this part(pre-execution of query) is use case driven. Underlying idea is to avoid the execution of emptyRowset by keeping InitialQueryOverridden=true for the search binding.

Raghu said...

Nice Post