The execute query is performed twice when Iterator caching is set to FALSE  (ADF)  Feb 5th, 2010

 

Summary of the problem

 

The scenario requires enforcing query execution when navigating between pages back and forth in order to display records that other users might have modified in the database.

 

The iterater has a property called  CacheResults , and it was set to false to disable query caching (this means that the each time a page is visited, the framework assumes that there is no cached records and therefore, the query needs to be executed again)

 

 

 

Create a simple ADF Form based on Dept table (page1)

Override the Dept ViewObject  ExecuteQuery() method and and a print statement to debug when the query is executed.

Add another JSF page  (page 2)

Create a button on page (1) that navigates to the second page  page (2)   through its Action property

Run  page (1)

Watch the console

1)       when page(1) is loaded and displayed the console will show the execute query print message

2)       when the button is pressed to navigate to page (2) the print message is printed again and the second page is shown

 

Why is the query executed the second time when you are leaving the first page?

 

 

I think it is just a NORMAL behaviour

 

Let us go through the sequence of events.

 

A URL pointing to an ADF is invoke

            1) The JSF/ADF lifecycle starts and executes  through its phases

            2) At a specific phase (depending on the REFRESH property) the Model is refreshed, and since the CACHE is false, the query is executed

            3) The page is rendered and the console shows that the execute query is performed – so far so good

            4) An Action is invoked on the page by pressing the button which should take us to a different page.  Due to the submit effect of the button , the page is submitted again to the JSF/ADF

            5) This is the tricky part, the page is submitted to the original URL , because the target URL is part of the ACTION processing. At this stage, the ACTION is not processed and will be processed by the SERVER.

            6) So, This is a POST BACK process, going again to the same JSF/ADF, and therefore, the phases will execute again, for the same page and the REFRESH condition is met and since the cache is false , the query executes once more, until phase 5 is reached when the ACTION in executed and the Second page is handled.  

 

 

We were driven into thinking that we the button is skipped, the behavious is similar to that of standard HTML and the ACTION is immediately invoked. The fact of the matter is the ACTION is invoked by the SERVER when the INVOKE APPLICATION is executed.  So whenever a page is submitted, the page is submitted back to the SERVER for further processing,  well, a side effect is the REFRESH takes place to point by to the ROW set.

 

A simplistic solution would be

To change the REFRESH CONDITON, so that REFRESH processing does not take place during the POST BACK cycle è ${adfFacesContext.postback==false}

 

Well, the extra execute query did not take place , however I ended with a warning

JBO-35007: Row currency has changed since the user interface was rendered

 

Indicating that the framework thinks that the model and the view are out of sync  (normally happens when you use the back button of the browser)

 

In 10.1.3.1, you can also disable current row validation on an iterator by iterator basic by setting the "StateValidation" property of an iterator to "false" without disabling it for all iterators in the page definition.

 

I have implemented this workaround and now in my simple application, I can navigate to another application without having to load the query twice

 

 Anyway, the Row Currency issue might be handled differently in 11g, try it for 11g and pls inform.

 

 

(Note: maybe it works better for your specific case to leave CACHING enabled, and force query execution programmatically )

 

RGDS