Sunday, September 6, 2009

Programmatical Reset for Query Results

If you are using ADF Faces Rich Client af:query component in your application, probably you have noticed that if View Criteria is declared not to query automatically, query results are not cleared when Reset button is pressed. There is no bug in this, its how framework works by default, however what to do if customer wants to have it differently. Today I will describe how you can use executeEmptyRowSet() method in order to clear query results.

Its recommended for performance reasons to avoid query automatically on large data sets, naturally we are not performing query by default in today sample application:


In order to have more complex case, let's declare required query criteria parameters. Finally, our query and results table will look like this:


In my sample, if user will press Reset button in af:query, results table will be cleared:


However, by default only query criteria parameters are cleared, results table will remain populated. In order to clear results table, I have implemented query operation listener in Backing Bean, where I'm calling Application Module method and triggering partial refresh for results table:


Custom method implemented in Application Module - doQueryResultReset() invokes executeEmptyRowSet() in order to clear rows from iterator. Additionally in our case, because we have required query criteria parameters, we need to remove View Criteria before invoking executeEmptyRowSet() and reapply it again:


Download sample application - QueryReset.zip

15 comments:

Jan Vervecken said...

hi

See also some executeEmptyRowSet() related forum messages here
http://forums.oracle.com/forums/message.jspa?messageID=3788453#3788453

regards
Jan Vervecken

Andrej Baranovskij said...

Thanks Jan,

Additionally can check here: http://andrejusb.blogspot.com/2009/08/oracle-adf-tuning-preventing-sql-query.html

Andrejus

Unknown said...

hi

in my case, i have one required field (adf 11.1.1.0.1)

i have cleared the view criteria (same as your with "removeviewcriteria".

but i have required field error message.

(something can be forget or not say ?)

thanks

Unknown said...

sorry, you can delete previous comment...

Anonymous said...

I want to capture query component mode(Basic | Advanced) in processQuery event listener method for QueryEvent as below:

public void processQuery(QueryEvent queryEvent) { // Add event code here... QueryDescriptor qdesc = queryEvent.getDescriptor(); String searchName = qdesc.getName(); String queryMode =?

I tried to get this value from getUIHints() map using UIHINT_MODE key. but getUIHints() returns empty map.

Andrej Baranovskij said...

Hi,

You can probably use ViewCriteriaHints and set property programmatically. Using setProperty() method on ViewCriteria object.

Regards,
Andrejus

Anonymous said...

Thanks Andrejus Baranovskis,


i want to handle reset query in the LOV item.

regards
Amr Rashed

Chaitanya said...

Andrejus,

When user clicks on clear, I need to set an Criteria Item with specific Value Derived at runtime. Is it possible to do so?

Thanks,
Chaitanya Varma

Karen said...

Is there a way to auto change the search results when the user chooses a new saved search rather then requiring user to click on the Search Button? What would I use to capture the change event for the user saved search selection -- as you have done with the Reset? Ideally there would be a button beside the saved search so user does not have to OPEN the search each time they want to change a saved search to a different query result set.

Unknown said...

Thank you Andrejus Baranovskis

It was very usefull. But can u pls give me a blog in which the advance link in ADF Quick Query panel Such that when user clicks the link it must change into advance mode of af:Query

Anonymous said...

Hi Andrejus,
I am using <f:facet name = "filer"
and I have a dropdown facet. When I clear my filter the table search clears off however the box that contains my dropdown still has the selected option for filtering. Any ideas on how to reset it back to blank?

Mark said...

Hi Andrejus,
Thanks for your many excellend ADF articles.
I have implemented a hierarchy viewer with search functionality (as per 26.7.3 in https://docs.oracle.com/cd/E23943_01/web.1111/b31974/graphs_charts.htm#ADFFD22229 ) which works well and shows the hierarchy initially at 3 levels (displayLevelsChildren="3"). If the user searches and selects a child node the hierarchy is re-drawn correctly with the selected node as the root node and child nodes also displayed.
I want the user to be able to reset the query so have added a button which calls a method (executeRootQuery) to try to reset the search and allow the user to easily go back to the original hierarchy (showing the root node and all children):

public String executeRootQuery() {
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
AttributeBinding searchStringAttr = (AttributeBinding)bindings.getControlBinding("pSearchString");
searchStringAttr.setInputValue(null);

AttributeBinding employeeIdAttr = (AttributeBinding)bindings.getControlBinding("pEmployeeId");
employeeIdAttr.setInputValue(null);

BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("ExecuteWithParams").execute();
//ExecuteWithParams refers to the Search in the bindings
BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("ExecuteWithParams1").execute();
//ExecuteWithParams1 refers to the Hierarchy in the bindings
return null;
}

BUT - When this hierarchy is redrawn it shows only the ROOT node and the user needs to manually expand the levels beneath it?
Any ideas on how to reset the hierarchy to display the root node and all the child nodes as it did before the initial searchy was executed??
Searching for the root node and selecting this using the Hierarchy Search function works fine but this would require the user to search for the root node and then double click on it - But I would like to have a single button to do this automatically...
Regards,
Mark

Andrej Baranovskij said...

I will need to research this.

Andrejus

HDS said...

Hi Andrejus,
Thank you for the post again. It has be informational as always. I was wondering if there is a way use Java/ADF API to invoke the processQuery instead of using EL expression "#{bindings.QueryByVacationRangeQuery.processQuery}"

Thanks,
HS

Andrej Baranovskij said...

To call from JSF UI level you need to use EL.

Andrejus