簡體   English   中英

嘗試將自定義行添加到gwt中的CellTable時出現空錯誤

[英]Null error when attempting to add custom row to CellTable in gwt

我有一個單元格表,用於輸出一些搜索結果。 單元格表使用列表數據提供程序來更新信息。 我想分開不同的部分,所以我試圖在不同的部分之間添加一個自定義行,該行具有一個跨所有列的單元格。 我正在擴展AbstractCellTableBuilder來執行此操作,但是當我使用TableRowBuilder和startRow()時,我的問題來了,調用startRow()返回一個空指針異常,指向AbstractCellTableBuilder.java:243,它引用了tbody。 因此,這使我相信我的單元格表未正確傳遞到AbstractCellTableBuilder中。 我對gwt和java的理解是非常基礎的,所以我可能只是不了解它應該如何工作,而該示例示例對於我來說卻相當復雜。 如果有人可以告訴我我在哪里搞砸,或者有任何更簡單的示例可能對我有所幫助,我將不勝感激!

我找到了一個類似的答案並嘗試實現它,這就是我想出的方法,但是它的答案不夠詳盡,不足以讓我完全理解它的工作原理。 這是我引用的內容: 使用GWT CellTableBuilder按需構建自定義行

編輯:

我如何向單元格表中添加普通行的基本格式

    searchProvider = new ListDataProvider<SearchColumn>();
    cellTable_2 = new CellTable<SearchColumn>();

    //Add columns to the cellTable
    searchProvider.addDataDisplay(cellTable_2);

    //What I call when adding a row to the cellTable using the ListDataProvider
    searchProvider.getList().add(new SearchColumn("",label,"","","","","","",""));

將CustomCellTableBuilder添加到單元格表:

    //Passing the CustomCellTableBuilder to the cell table
    CustomCellTableBuilder buildRow = new CustomCellTableBuilder();
    cellTable_2.setTableBuilder(buildRow);

用於添加自定義行的CustomCellTableBuilder:

    public class CustomCellTableBuilder extends AbstractCellTableBuilder<SearchColumn>{
    public CustomCellTableBuilder() {
        super(cellTable_2);
    }

    @Override
    protected void buildRowImpl(SearchColumn rowValue, int absRowIndex){
       //building main rows logic 

        if (labelrow == 1){
            System.out.println("Going to build extra row if");
            buildExtraRow(absRowIndex, rowValue);
        }
        else {
            System.out.println("Getting into normal buildRow");
            buildRow(rowValue,absRowIndex);
        }
    }

    private void buildExtraRow(int absRowIndex, SearchColumn rowValue){

        start(true);
        TableRowBuilder row = startRow();
        TableCellBuilder td = row.startTD().colSpan(getColumns().size());
        td.text("Testing this out").endTD();
        row.endTR();
    }}

我認為您應該在調用startRow()之前先調用start(true) ,因為tbody已初始化為null。 Start()調用會將tbody初始化為HtmlBuilderFactory.get().createTBodyBuilder()

消息來源沒有說謊。

就像這樣:

private void buildExtraRow(int absRowIndex, SearchColumn rowValue) {
        start(true); // true makes builder to rebuild all rows
        TableRowBuilder row = startRow();
        // whatever
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM