incubator-adffaces-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cosma Colanicchia" <>
Subject Re: af:table and single selection, how to get the selected row?
Date Fri, 07 Jul 2006 09:36:03 GMT
Ok, I'm using a binding to find the selected row.

But I have another problem: I need to "preset" the selected row to
some value. How I can do this? I've found this doc about the ADF Faces
table at [1]:

"The current selection of rows on the Table can be programmatically
inspected and modified via the  RowKeySet  object obtained by calling
getSelectionState()  on the Table. The rowKeys of the currently
selected rows can be accessed via the  getRowKeyIterator()  method on
the  RowKeySet  instance. To programmatically change a selection, the
appropriate row must first be made current by calling
setRowIndex(...)  or  setRowKey(...)  on the Table. Then the selection
of the row may be changed by calling  add()  or  remove()  on the

I can't find the getSelectionState(), but I tried this way:

public RowKeySet getSelectedRow() {
  MyObjectType valueToSelect = getSelectedValueSomeHow();
  if (valueToSelect != null) {
    CoreTable table = _boundTable; // _boundTable is set with a binding
    int rows = _boundTable.getRows();
    for (int i=0; i<rows; i++) {
      // Set the current row to check the RowData
      MyObjectType rowData = (MyObjectType) _boundTable.getRowData();
      if (rowData .equals(valueToSelect )) {
        // Row found, get the rowkey and return it
        RowKeySetImpl keySet = new RowKeySetImpl();
        return keySet;
 // Row to select not found
  return null;

This method is bound to the selectedRowKeys attribute of <af:table>.
The problem is that, when _boundTable.setRowIndex(i) is called, the
getSelectedRow() method is again called (looks like it is internally
saving some state), causing an infinte loop.

On the other hand, I have no way to obtain the RowKey of a row without
setting it as current and calling getRowKey(). The object bound to the
"value" attribute is a simple ArrayList, so I think that rowkeys are
automatically generated.

I'm stack and documentation is lacking or obsolete. Can anyone help me? TIA

2006/7/7, Cosma Colanicchia <>:
> Hi,
> I'm trying to do a single row selection with <af:table>. I used a
> rowSelection attribute that made the radio button display, but in the
> OTN docs I haven't found its documentation.. is it a Trinidad
> enhancement?
> My question is: with an <af:commandButton> outside of the table, how
> can I get the currently selected row? Is it simpler if I put the
> button in the table footer? Can't find any docs on this.
> Thank you
> Cosma

View raw message