Getting
Ref of the View Object referenced by the current Iterator binding for One
iterator page without knowing the name of the iterator
In a previous article (Playing around with ADF datacontrol), it was shown that you can get the ApplicationModule object without having to know the name of the Data Control
Instead of this line of code
AppModuleImpl
appmodule =
(AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
The following code is written
DCBindingContainer binding = (DCBindingContainer)ADFUtils.getBindingContainer();
DCDataControl cDataControl = binding.getDataControl();
ApplicationModule AM =cDataControl.getApplicationModule();
Now and in order to be more generic in code writing, here is
a code that will get you the View Object that is bound to the iterator binding
of a page.
This code will work for simple pages that contains one
iterator binding because if there are two iterator bindings within the same
page definition, you will need to specify which one you
want
// this piece of code will get all iterator bindings for the page and will check that there is only ONE iterator binding, this implementation is much faster than iterator through the iterator and count it
ArrayList
arr = binding.getAllIterBindingList();
if (arr instanceof Collection<?>) {
int size
= (arr).size();
System.out.println(size);
if (size != 1) {
System.out.println("not single iterator ok");
}
//
practically, should through an exception
else {
//
once you are sure there is only one iterator, then you fetch the first
one
DCIteratorBinding
ItrBind = (DCIteratorBinding)arr.get(0);
// here you get the viewobject that the iterator references without its name
ViewObject
voData = ItrBind.getViewObject();
Long range = voData.getEstimatedRowCount();
System.out.println("Range
:" + range.toString());
System.out.println("VO
name " + voData.getDefFullName());
}
}
else
{
System.out.println("not
a collection ");
}
You can now create a method that
shall return the ViewObject Name
public ViewObject getCurrentIteratorVO
() {
DCBindingContainer
binding = (DCBindingContainer)ADFUtils.getBindingContainer();
ArrayList arr = binding.getAllIterBindingList();
if (arr instanceof Collection<?>) {
int size
= (arr).size();
System.out.println(size);
if (size != 1) {
System.out.println("not single iterator ");
// practically, should through an
exception
}
else {
DCIteratorBinding
ItrBind = (DCIteratorBinding)arr.get(0);
ViewObject
voData = ItrBind.getViewObject();
Long range = voData.getEstimatedRowCount();
System.out.println("Range
:" + range.toString());
System.out.println("VO
name " + voData.getDefFullName());
return voData;
}
} else {
System.out.println("not
a collection ");
}
return null;
}
Call the method
public String cb6_action() {
// Add event code here...
ViewObject vv = getCurrentIteratorVO();
return null;
}
The output is
1
Range :14
VO name model.EmpView