I write solutions to the problems I can't find much about elsewhere on the Web, also some code/script snippets that are absolutely awesome and make my life easier. Will be glad if someone finds these posts interesting and helpful!

Monday, May 3, 2010

Clear an iterator in ADF 10g

The mission is to empty out an iterator without setting its Refresh attribute to “never” and consequentially executing it manually. What I ended up doing, when I needed this once, was adding a parameter to the query WHERE clause (something like “and 1 = nvl(:param, 1)”) and invoking it with a zero when I needed it empty. Apparently there is an easier way.
Say the iterator to clear is defined in the pageDef as:
<iterator id="City1Iterator" RangeSize="-1"
Binds="City1" Refresh="always"
DataControl="AppModuleDataControl"/>
view raw gistfile1.xml hosted with ❤ by GitHub

Then the code in the backing bean would look like:
javax.faces.context.FacesContext ctx = javax.faces.context.FacesContext.getCurrentInstance();
javax.faces.el.ValueBinding bind = ctx.getApplication().createValueBinding("#{data}");
oracle.adf.model.BindingContext bindingContext = (oracle.adf.model.BindingContext) bind.getValue(ctx); //resolve binding context
oracle.adf.model.binding.DCDataControl dataControl = bindingContext.findDataControl("AppModuleDataControl");//find data control by name (defined in DataBindings.cpx) from BindingContext
/*
* finally get the View Object instance which the iterator is bound to (see the attribute Binds in the iterator definition in the pageDef)
* then invoke the magic method executeEmptyRowSet on it
*/
((AppModuleImpl) dataControl.getDataProvider()).getCity1().executeEmptyRowSet();
view raw gistfile1.java hosted with ❤ by GitHub

That’s it. Hope this helps!

No comments:

Post a Comment