Friday, May 1, 2015

Get Selected Row of ADF Tree

I needed to get some information contained in the selected row of an ADF Tree component.

/* START PRESERVE DEFAULT ADF SELECT BEHAVIOR 
 * Courtesy of Frank Nimphius - https://blogs.oracle.com/jdevotnharvest/entry/how_to_read_data_from */

FacesContext fctx = FacesContext.getCurrentInstance();
Application application = fctx.getApplication();
ELContext elCtx = fctx.getELContext();
ExpressionFactory exprFactory = application.getExpressionFactory();

MethodExpression me = null;
me = exprFactory.createMethodExpression(elCtx, adfSelectionListener, Object.class, new Class[] {SelectionEvent.class}); 
me.invoke(elCtx, new Object[] { selectionEvent });  
/* END PRESERVE DEFAULT ADF SELECT BEHAVIOR */

RichTree tree = (RichTree)selectionEvent.getSource();
TreeModel model = (TreeModel)tree.getValue();

// get selected nodes
RowKeySet rowKeySet = selectionEvent.getAddedSet();
Iterator rksIterator = rowKeySet.iterator();

while (rksIterator.hasNext()) {
   List key = (List)rksIterator.next();
   JUCtrlHierBinding treeBinding = null;
   CollectionModel collectionModel = (CollectionModel)tree.getValue();
   treeBinding = (JUCtrlHierBinding)collectionModel.getWrappedData();
   JUCtrlHierNodeBinding nodeBinding = null;
   nodeBinding = treeBinding.findNodeByKeyPath(key);
   Row row = nodeBinding.getRow();
   // Get the LexisAccountNumber and enable the delete image link
   String value = row.getAttribute("someAttribute").toString();
}

No comments:

Post a Comment