Search code examples
gwtfielduibinder

gwt uiBinder ui:field access problem


I have this in my ui.xml file:

<g:Button ui:field="saveButton"/>

This is in my view class:

@UiField
Button saveButton;

@Inject
public MyView() {

    saveButton.setText("Save");

    initWidget(binder.createAndBindUi(this));
}

If I run it as is, I get blank screen. But if I remove the saveButton.setText("Save"); the button will come up but without any text in it. BTW I'm using mvp4g

Any idea why this is happening?


Solution

  • @UiField without provided have to go under the initWidget call and @UiField(provided = true) has to go above the initWidget call.

    @Inject
    public MyView() {    
        // here go all UiFields with provided=true 
        initWidget(binder.createAndBindUi(this));
        // here go all UiFields without provided
        saveButton.setText("Save");
    }