2

I'm using GWT 2.4. I have a com.google.gwt.user.cellview.client.CellTable widget, but I'm having trouble figuring out a programmatic way to get the String headers after the widget is constructed. I add column data like so ...

tableWidget.addColumn(column, header); 

where column is a com.google.gwt.user.cellview.client.Column object and header is a String. how can I get the header from either the column or cell table objects?

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Dave
  • 15,639
  • 133
  • 442
  • 830

3 Answers3

3

For using protected method you can create a custom class, like this:

public class CustomCellTable extends CellTable {

    /* some code... */

    /* Method for access to header */
    public TableSectionElement getHeadElement() {
          return this.getTableHeadElement();
    }

    /* some code... */

}
Ronan Quillevere
  • 3,699
  • 1
  • 29
  • 44
user1051870
  • 913
  • 1
  • 10
  • 21
  • I really appreciate this response. For some background, the reason I want to access the headers is to verify in my JUnit test that the widget is being created properly. I don't need to access the headers programatically in my core code. If creating an extra class is the only way to get at them, them I'm in, but I wanted to throw that out there. – Dave Nov 21 '11 at 16:06
  • Sorry, but I see no other way than to create an intermediate class for your CellTable. GWT is not very flexible tool (so I no longer use it). – user1051870 Nov 21 '11 at 18:57
1

Try to use getTableHeadElement() method of com.google.gwt.user.cellview.client.CellTable. See documentation.

user1051870
  • 913
  • 1
  • 10
  • 21
  • 2
    Per the documentation, the method you suggest isn't visible (it's protected). So its impossible to access. – Dave Nov 21 '11 at 13:52
0

If you want to have more control on your header, maybe you can use the following method when adding your column to your table. Thus you could keep a pointer on your header to do whatever you want on it.

public void addColumn(Column<T, ?> col, Header<?> header)

Then create your own Header or use a TextHeader for example.

TextHeader textHeader = new TextHeader("headerTitle");
myTable.addColumn(myColumn, textHeader);

But if the goal is to verify that the widget is being created properly I guess that it is GWT responsibilityto do that. I do not see the point of testing GWT behavior. It is already done by GWT. Of course there might be some bugs that you can find.

see other post here also if your want to check or override some css style : look-up-gwt-celltable-header-style-s

Community
  • 1
  • 1
Ronan Quillevere
  • 3,699
  • 1
  • 29
  • 44