2013-01-09 21 views
3

我的GWT項目中有一個CellTable,每行都有一個CheckBox。 不知何故我需要遍歷cellTable中的所有行,並且需要 來檢查每行的CheckBox是否被選中。帶有CheckBox的GWT CellTable獲取所有選中的框

我不知道該怎麼做,我找不到任何顯示如何。

private Column<Article, Boolean> showPinColumn = new Column<Article, Boolean>(new CheckboxCell()) { 
    public Boolean getValue(Article object) { 
     return false; 
    } 
}; 
+0

可能重複[GWT:如何獲取cellTable的複選框的值](http://stackoverflow.com/questions/12476521/gwthow-to-get-the-value-of-a-checkbox-單元格) –

回答

4

第1步 - 您應該修復showPinColumn代碼並使用FieldUpdater實際更新對象。

final CheckboxCell cbCell = new CheckboxCell(); 
Column<Article, Boolean> cbColumn = new Column<Article, Boolean>(cbCell) { 
    @Override 
    public Boolean getValue(Article object) { 
     System.out.println("method getValue() - " + object.id + " - " + object.checked); 
     return object.checked; 
    } 
}; 

cbColumn.setFieldUpdater(new FieldUpdater<Fieldupdater.Article, Boolean>() { 
    @Override 
    public void update(int index, Article object, Boolean value) { 
     System.out.println("method update() - " + object.id + " - " + value); 
    } 
}); 

第2步 - 您應該只遍歷每個在「名單」的項目,你設置成celltable併爲您在文章布爾屬性。

+0

謝謝,它有效;) – user1882812

相關問題