Skip to main content

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]


Anonymous said…
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.

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.

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…

Happy New Year 2018 !

We can't go back and change the beginning, but we always can start where we are and change the ending. Believe in yourself and you will be unstoppable!

Wishing you and your family a very happy new year 2018 !!!