开发者

Iterate through all rows in an ADF richtable

开发者 https://www.devze.com 2023-04-11 05:40 出处:网络
I have a table that displays two columns from a table and a third with checkboxes the user can check and uncheck.

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

精彩评论

暂无评论...
验证码 换一张
取 消