[英]Null error when attempting to add custom row to CellTable in gwt
I have a Cell Table that I am using to output some search results. 我有一个单元格表,用于输出一些搜索结果。 The cell table uses a list data provider to update info.
单元格表使用列表数据提供程序来更新信息。 I want to separate different sections so I am attempting to add a custom row in between different sections that has one cell that spans all of the columns.
我想分开不同的部分,所以我试图在不同的部分之间添加一个自定义行,该行具有一个跨所有列的单元格。 I am extending AbstractCellTableBuilder to do this, but my issue comes when I use TableRowBuilder and startRow(), calling startRow() returns a null pointer exception, to AbstractCellTableBuilder.java:243, which refers to tbody.
我正在扩展AbstractCellTableBuilder来执行此操作,但是当我使用TableRowBuilder和startRow()时,我的问题来了,调用startRow()返回一个空指针异常,指向AbstractCellTableBuilder.java:243,它引用了tbody。 So this is leading me to believe that my cell table is not getting passed into AbstractCellTableBuilder properly.
因此,这使我相信我的单元格表未正确传递到AbstractCellTableBuilder中。 My understanding of gwt and java is pretty basic, so I might just not be understanding how exactly this is supposed to work, and the showcase example is pretty complicated for me to understand.
我对gwt和java的理解是非常基础的,所以我可能只是不了解它应该如何工作,而该示例示例对于我来说却相当复杂。 If anyone can tell where I'm messing up or has any simpler examples of this that might help me I would appreciate it!
如果有人可以告诉我我在哪里搞砸,或者有任何更简单的示例可能对我有所帮助,我将不胜感激!
I had found a similar answer and tried to implement it, and that is how I came up with what I have, but it answer wasn't quite detailed enough for me to fully understand how it works. 我找到了一个类似的答案并尝试实现它,这就是我想出的方法,但是它的答案不够详尽,不足以让我完全理解它的工作原理。 Here is what I referenced: Building a custom row on demand with GWT CellTableBuilder
这是我引用的内容: 使用GWT CellTableBuilder按需构建自定义行
EDITED: 编辑:
Basic format of how I add normal rows to the cell table 我如何向单元格表中添加普通行的基本格式
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,"","","","","","",""));
Adding the CustomCellTableBuilder to the cell table: 将CustomCellTableBuilder添加到单元格表:
//Passing the CustomCellTableBuilder to the cell table
CustomCellTableBuilder buildRow = new CustomCellTableBuilder();
cellTable_2.setTableBuilder(buildRow);
The CustomCellTableBuilder for adding custom rows: 用于添加自定义行的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();
}}
I think you should call start(true)
before calling startRow()
because tbody
is initialized to null. 我认为您应该在调用
startRow()
之前先调用start(true)
,因为tbody
已初始化为null。 Start() call will initialize tbody to HtmlBuilderFactory.get().createTBodyBuilder()
. Start()调用会将tbody初始化为
HtmlBuilderFactory.get().createTBodyBuilder()
。
The source doesn't lie. 消息来源没有说谎。
Just like that: 就像这样:
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.