Question

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. So this is leading me to believe that my cell table is not getting passed into AbstractCellTableBuilder properly. 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. 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

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:

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

The CustomCellTableBuilder for adding custom rows:

    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();
    }}
Was it helpful?

Solution

I think you should call start(true) before calling startRow() because tbody is initialized to null. Start() call will initialize tbody to 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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top