How to set GWT Flextable first row (i.e heading) declaratively using UiBinder?

4.9k Views Asked by At

I want my table to have the following static column headings: "Name", "Surname", "DOB", but I want to declare them in *.ui.xml (rather than in code).

Right now, I'm doing it via code like this:

public PersonViewImpl extends Composite implements PersonView {
    /*Lots of code removed for clarity*/

    @UiField (provided = true) FlexTable personTable;

    public PersonViewImpl(){
        personTable.setText(0, 0, "Name");
        personTable.setText(0, 1, "Surname");
        personTable.setText(0, 2, "DOB")    
    }
}

I have this in my PersonView.ui.xml

<g:FlexTable ui:field="personTable" />

I've googled for hours, but still no go.

3

There are 3 best solutions below

0
On

You cannot set FlexTable's cell elements in UI Binder, probably you should have your own custom widget which renders tr and td. For example, like explained here: GWT table row as UiBinder

0
On

Missing initWidget( uiBinder.createAndBindUi(this) ); on first line of constructor.

try this:

public class PersonViewImpl extends Composite implements PersonView {
    /*Lots of code removed for clarity*/

    @UiField (provided = true) FlexTable personTable;

    public PersonViewImpl(){
        initWidget( uiBinder.createAndBindUi(this) );
        // TODO your code
    }
}
0
On

when you declare provider = true, the ui binder not instance the object, you need to instance it in your java class the right code is:

public PersonViewImpl(){
    // enter code here
    personTable = new FlexTable();
    personTable.setText(0, 0, "Name");
    personTable.setText(0, 1, "Surname");
    personTable.setText(0, 2, "DOB");
}