ADF View Objects with Dynamic Where Clauses
While working on a recent modernization project I came across a scenario in which a View Object used by a page had a different where clause depending on one of the values passed in. All in all, not too big of a deal, but because the where clause used a number of parameters and the parameters used changed along with the where clause it introduced some complications. So to save you the trouble I thought I'd write about a couple of them here.
First of all, it is easy enough to to create a method in an Aplication Module implementation class that adjusts the where clause to what you need using the ViewObject.setWhereClause(String whereClause) method. To set the parameters you need to use the ViewObject.setNamedWhereClauseParam(String paramName, Object paramValue) method. What I found was that I had to have the parameters set at Bind Variables in the View Object and they must have their required property set to true, otherwise they are not really bind variables.
What that means is that to execute the query, it must contain all of the bind variables even if they are not being used. That means putting them in the where clause all the time. To accomplish this for bind variables that were not used, I just put something like "and :par1 = null" and set the value to null using the above method.
This works fine except that since the bind variables are not in the original query definition another problem was encountered. As soon as the task flow opened, the first thing it had to do was run the method I defined in the Application Module, unfortunately that did not happen. Instead the first thing that happened was that the View Object executed and returned an error because the bind variables were not in the query.
Apparently in order for my method to work, I needed a page definition file that allowed my method to access my View Object's iterator. Because this iterator was in the page definition file, ADF executed the query upfront even though nothing that used it was being called yet. In order to fix this I set the refresh property of the iterator in the page defintion to "never". This means that the iterator will not execute unless refresh() or execute() are called programattically on the View Object. Of course this happens in the Application Module method that sets up the where clause after the where clause has been defined with the parameters in it.
That's it, simple enough once you realize what is happening, but a little frustrating before that light bulb goes on!
Reader Comments