2011-10-05 39 views
2

我有一个表格显示表格中的两列和第三个复选框,用户可以选中并取消选中。迭代ADF丰富表中的所有行

附近是一个提交更改按钮,当单击该按钮时,我想遍历表中的行并基于复选标记的状态采取不同的操作。现在表格是不可选的。

我已经摆弄了一整天,现在我想我可能只需要更改为ADF多选表,而不是一列复选框只是允许用户选择和取消选择和使用selectedrows集合采取行动。

任何想法?

回答

3

我想出了一个不太脏的工作。鉴于任何时候你都可以从RichTable对象中获得一组选定的行,我决定可以暂时将所有行设置为选中状态并获取所选行。

警告:在我当前的应用程序中,我正在处理的表未设置为允许选择,因此我不必担心清除选择,因为在刷新完成后它会被抛出。

// 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 
    } 

选择,我发现在AMIS blogs所有行的功能是

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); 
} 
+1

或者你可以在一个时间过程中选择一行并继续。最后恢复旧的'RowKey'。 – AppleGrew