2011-10-05 20 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