One question, which can be fairly common among new ADF developers, whats the best way to programatically loop through a View object's rows without affecting the View Object's root RowSetIterator? After all, you have what seems to be too many ways to do this:
- ViewObjectImpl.getAllRowsInRange, returning Row[]
- ViewObjectImpl.getRowSet, returning RowSet
- ViewObjectImpl.getRowSetIterator, returning RowSetIterator
- ViewObjectImpl.createRowSetIterator, returning RowSetIterator
While all ways could work per the above, only one is the best, ViewObjectImpl.createRowSetIterator. It delivers the most consistent results and it won't affect the currently selected row of the View Object.
Here's how we use it:
See this example, where i look up a view object row by attribute value:
- Create RowSetIterator from your View Object class: ViewObjectImpl.createRowSetIterator()
- Reset the RowSetIterator - just in case
- Loop through the iterator: while(RowSetIterator.hasNext()) { .. }
- After your loop is finished, close the RowSetIterator: RowSetIterator.closeRowSetIterator()
See this example, where i look up a view object row by attribute value:
public Row getRowByAttribute(ViewObjectImpl vo, String attributeName, Object attributeValue) {
RowSetIterator rsi = vo.createRowSetIterator(null);
rsi.reset();
Row currRow=null;
while(rsi.hasNext()) {
currRow = rsi.next();
if (currRow.getAttribute(attributeName).equals(attributeValue)) {
rsi.closeRowSetIterator();
return currRow;
}
}
rsi.closeRowSetIterator();
return null;
}
Happy JDeveloping!