Wednesday, January 18, 2012

ADF common errors: How to get selected row from table ?

In many blogs I found above question and solution like this:

FacesCtrlHierBinding rowBinding = (FacesCtrlHierBinding) tab.getSelectedRow();
Row rw = rowBinding.getRow();


RichTable _table = (RichTable ) selectionEvent.getSource();
CollectionModel model = (CollectionModel ) _table.getValue();
FacesCtrlHierBinding _binding = (FacesCtrlHierBinding) model.getWrappedData();
FacesCtrlHierBinding.FacesModel treeModel = (FacesCtrlHierBinding.FacesModel) _binding.getTreeModel();

On first sight FacesCtrlHierBinding exposes the convenient methods you need. But the solution is invalid. You shouldn't use FacesCtrlHierBinding and FacesCtrlHierNodeBinding directly cause they are internal ADF Faces component model for tree, table and treeTable.

You can use EL in Java: #{bindings.myEntityView.treeModel.makeCurrent}:
  • Easy to use
  • Does it right for all Data Control types
  • Requires knowledge about the PageDef definition

Use JUCtrlHierBinding or JUCtrlHierNodeBinding
  • No knowledge about binding layer is required
  • Needs more code to write
By example:

RichTable _table = (RichTable ) selectionEvent.getSource();
CollectionModel model = (CollectionModel ) _table.getValue();
JUCtrlHierBinding _binding = (JUCtrlHierBinding) model.getWrappedData();
DCIteratorBinding iteratorBinding = _binding.getDCIteratorBinding();
Object _selectedRowData = _table´.getSelectedRowData();
JUCtrlHierNodeBinding node = (JUCtrlHierNodeBinding) _selectedRowData ;
Key rwKey = node.getRowKey();


  1. Hi I have a tree table. I want to get the multiple selected values.I have created the tree table programmatically. Can you tell me how can I get the selected values.

  2. ADFUtils.invokeEL("#{bindings.Employee1.collectionModel.makeCurrent}", new Class[]{SelectionEvent.class}, new Object[]{selectionEvent});

  3. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.