2014-12-29 30 views
0

我無法弄清爲什麼我的render方法沒有被調用。這是我的定製單元格,它將AbstractCell擴展爲最簡單的形式。CellList中的GWT自定義單元格 - render()未被調用

public class FormHistoryCell<T> extends AbstractCell<T> { 

@Override 
public void render(com.google.gwt.cell.client.Cell.Context context, T value, SafeHtmlBuilder sb) { 

    System.out.println("Rendering customer cell..."); 

    if (value == null) { 
     return; 
    } 
} 

}

這裏是我的代碼snipet它創建「FormHistoryCell」的實例,並試圖將其添加到CellList。

@UiFactory 
CellList<FormHistoryCell> initList() { 
    FormHistoryCell formHistoryCell = new FormHistoryCell(); 
    CellList historyList = new CellList<FormHistoryCell>(formHistoryCell); 

    return historyList; 
} 

我曾嘗試不同的東西,如添加一個構造函數一個字符串參數等構造函數被調用,但渲染方法是沒有的。看看它擴展的Abstract類,似乎render方法在「setValue」方法中被調用,但沒有看到其他自定義單元格擴展中被調用的渲染方法似乎被調用的很好。我確信我在這裏錯過了一些明顯的東西,但無法弄清楚什麼。請幫忙。

+2

我想你需要在CellList中設置一些數據以便渲染被調用 – outellou

回答

1

根據您所提供的代碼,沒有理由對瀏覽器撥打您的手機的render方法。您只需將對象FormHistoryCell的引用傳遞給您的CellList。僅當瀏覽器必須顯示單元格及其內容時才需要使用render方法。當你向你的CellList添加數據時就會發生這種情況,就像@outellou建議的那樣。