Friday, February 8, 2013

Adf Mobile - Iterate through all the rows in tree binding using CollectionModel

Scenario is how to iterate through all the rows in tree bindings using managed bean method, using collectionModel we can get the rows. collectionModel exposes a collection of data, EL expressions used within a component that is bound to a collectionModel can be referenced with a row variable, which will resolve the expression for each element in the collection.

Here is the code below which iterate through the rows using collection model. Make sure the departments should be of type Tree binding.
ValueExpression ve1 =
 AdfmfJavaUtilities.getValueExpression("#{bindings.departments.collectionModel}", AmxCollectionModel.class);
AmxCollectionModel model = (AmxCollectionModel)ve1.getValue(AdfmfJavaUtilities.getAdfELContext());

StringBuffer deptNamesString = new StringBuffer();
Object[] myArr = model.getKeys();
for (int x = 0; x < myArr.length; x++) {
 Object myObj = myArr[x];
 Map provider = (Map)model.getProviders().get(myObj);
 String val = provider.get("deptName").toString();
 deptNamesString.append("," + val);
//Populating the pageFlowscope variable, which will be displayed in amx page
ValueExpression ve2 =
 AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.departmentNameString}", String.class);
ve2.setValue(AdfmfJavaUtilities.getAdfELContext(), deptNamesString.substring(1));
You can download the sample workspace from here. Application screen looks like below when it deployed and run on Android Device/Emulator. In first screen DepartmentNames values will be empty after clicking on Execute button, in managed bean method using collection model rows will be iterated and stored in pageFlowScope variable, same variable value will be displayed on the screen.


  1. Good post Deepak! Thank you.

  2. Hi, How to bind the Oracle MAF collectionModel into java bean class. The collectionModel contain lot of text box. textarea, select box, and radio button... how to collect all the values in one submit button