1

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();
    }}
Community
  • 1
  • 1
ryooan
  • 13
  • 4
  • The problem is in how you're using your `CustomCellTableBuilder`. Why aren't you giving it to the `CellTable`? – Thomas Broyer Jan 06 '14 at 00:39
  • Sorry, I'm not sure I understand what you mean. From what I've been able to tell I'm supposed to pass the CellTable to the AbstractCellTableBuilder, which is what super(cellTable_2) is supposed to do as far as I understand. I didn't pass cellTable_2 when I created a new instance of CustomCellTableBuilder because this is all part of a subclass and cellTable_2 was inherited so I didn't know if it was necessary. Sorry if my terminology is confusing or wrong, I'm just making this program as a hobby so I'm not very good at this stuff. – ryooan Jan 06 '14 at 03:00
  • The way you generally use a `CellTableBuilder` is to pass it to the `CellTable`'s [`setTableBuilder`](http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/cellview/client/AbstractCellTable.html#setTableBuilder%28com.google.gwt.user.cellview.client.CellTableBuilder%29) and the `CellTable` uses it (calling the methods in the right order) to build/render the table. That's not what you're doing, so at least show more of your code. – Thomas Broyer Jan 06 '14 at 09:58
  • Now that it's not getting stuck on null anymore I think I understand what you are saying, since it still isn't drawing the rows that I want. I added the CustomCellTableBuilder using setTableBuilder to the CellTable now, but it still isn't showing any of the cells. Is the problem that I am also using a ListDataProvider for the CellTable? Can these not both be applied to the same CellTable or is there some other issue I'm missing? I'll add some more details to the bottom of my original post so you can see. – ryooan Jan 07 '14 at 07:00
  • The question is: why are you calling `buildRow` yourself?! The expected usage of `CellTableBuilder` is to let the `CellTable` call all of its methods when it needs to render its data (whether it comes from a `ListDataProvider` or whatever); you create the `CellTable`, replace its `CellTableBuilder` with your custom one and then feed data into it, and the `CellTable` renders that data using the `CellTableBuilder`. – Thomas Broyer Jan 07 '14 at 11:26
  • Okay I think I see what you are saying, I just don't know how to implement that. I updated my code above to show what I am most currently doing. So for the normal rows I am using the ListDataProvider and calling searchProvider.getList().add(new SearchColumn()) to add a row to the table. But what I don't understand is how to make it so that it will use the CustomCellTableBuilder. I have those print statements inside buildRowImpl and I'm not seeing them print out so it doesn't seem like it's using my custom builder at all and I'm not understanding why. – ryooan Jan 08 '14 at 06:39

1 Answers1

1

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
}
Nigel Tufnel
  • 11,146
  • 4
  • 35
  • 31
  • Aha! This gets me past the null error, thank you! It's not quite working as intended yet but I think that fixes this issue. – ryooan Jan 07 '14 at 05:49