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?
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);
}