Iterate through all rows in an ADF richtable

17,789

I came up with a work around that isn't too dirty. Given that at anytime you can get a set of selected rows from the RichTable object I decided I can temporarily set all rows to selected and get the selected rows set.

WARNING: In my current application the table I'm dealing with is not set to allow selection so I don't have to worry about clearing the selection since it gets thrown out after the refresh is completed.

    // set all rows in the table to selected so they can be iterated through
    selectAllRowsInTable( rolesGrantedAndAvailableTable );
    RowKeySet rSet = rolesGrantedAndAvailableTable.getSelectedRowKeys();

    Iterator selectedEmpIter = rSet.iterator();
    DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding roleIter = bindings.findIteratorBinding("usersGrantedAndAvailableRolesView1Iterator");
    RowSetIterator roleRSIter = roleIter.getRowSetIterator();

    // iterate through all rows checking checkmark status and deciding if the roles need to be granted, revoked, or no action be taken
    while(selectedEmpIter.hasNext())
    {
        // Do your stuff with each row here
    }

the function for selecting all rows which I found at AMIS blogs is

public void selectAllRowsInTable( RichTable rt )
{
      RowKeySet rks = new RowKeySetImpl();
      CollectionModel model = (CollectionModel)rt.getValue();
      int rowcount = model.getRowCount();

      for( int i = 0; i < rowcount; i++ )
      {
            model.setRowIndex(i);
            Object key = model.getRowKey();
            rks.add(key);
      }

      rt.setSelectedRowKeys(rks);
}
Share:
17,789
FaultyJuggler
Author by

FaultyJuggler

"The best way to complain is to make things" — James Murphy Senior Product Owner, Solutions Architect, and Agile Coach with over a dozen successful deployments. I empower teams to reach their collective potential while embracing diversity and constructive criticism in a supportive work environment. I've built effective teams across startups, charity organizations, and military projects. Currently hoping to have impact in Healthcare and civic participation.

Updated on June 04, 2022

Comments

  • FaultyJuggler
    FaultyJuggler almost 2 years

    I have a table that displays two columns from a table and a third with checkboxes the user can check and uncheck.

    Nearby is a submit changes button, when that button is clicked I want to iterate down the rows of the table and based on the checkmark's status take different actions. Right now the table is non-selectable.

    I've been fiddling with this for over a day now and I'm thinking I may just have to change to an ADF multiple selection table and instead of a column of checkboxes simply allow the user to select and unselect and use the selectedrows collection to take action.

    Any ideas?

  • AppleGrew
    AppleGrew about 12 years
    Or you can select one row at a time process it and continue. At the end restore the old RowKey.