繁体   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