0
votes

I have followed the GettingStarted on the GWTP tutorial

http://code.google.com/p/gwt-platform/wiki/GettingStarted

but unfortunately handlers not working, getUiHandlers() return null and exception stacktrace is same as in:

How to use UiHandlers of GWT Platform? .

View Class

public class AView extends ViewWithUiHandlers<AUiHandlers> implements APresenter.Display {

    @UiTemplate("AView.ui.xml")
    interface AViewUiBinder extends UiBinder<Widget, AView> {}
    private static AViewUiBinder uiBinder = GWT.create(AViewUiBinder.class);

    @UiField Button saveBtn;
    @UiField Button cancelBtn;

    @UiField DivElement errorDiv;

    private Widget widget;

    @Inject
    public AssetView() {
        widget = uiBinder.createAndBindUi(this);
    }

    public Widget asWidget() {
        return widget;
    }

    // Implementation: Presenter's Display methods
    public void setErrorDivText(String msg) {
        errorDiv.getStyle().setDisplay(Display.BLOCK);
        errorDiv.setInnerText(msg);     
    }

    // Handlers 
    @UiHandler("saveBtn")
    void onSaveButtonClick(ClickEvent event) {
        if(getUiHandlers() != null) {
            getUiHandlers().onSaveButtonClick();
        }
    }

    @UiHandler("cancelBtn")
    void onCancelButtonClick(ClickEvent event) {
        if(getUiHandlers() != null) {
            getUiHandlers().onCancelButtonClick();
        }
    }
}

Handler Interface

public interface AUiHandlers extends UiHandlers {
    void onSaveButtonClick();
    void onCancelButtonClick();
}

Presenter

public class APresenter extends Presenter<APresenter.Display, APresenter.AssetProxy> implements AUiHandlers {

    public interface Display extends View, HasUiHandlers<AUiHandlers> { 
        public void setErrorDivText(String msg);
    }

    @ProxyStandard
    @NameToken(NameTokens.ASSET)
    public interface AssetProxy extends ProxyPlace<AssetPresenter> {}

    @Inject
    public AssetPresenter(EventBus eventBus, Display view, AssetProxy proxy) {
        super(eventBus, view, proxy);

        getView().setUiHandlers(this);
    }

    @Override
    protected void onBind() {
        super.onBind();
    }

    @Override
    protected void revealInParent() {
        RevealRootContentEvent.fire( this, this );
    }

    public void onSaveButtonClick() {
        getView().setErrorDivText("Save clicked.");
    }

    public void onCancelButtonClick() {
        getView().setErrorDivText("Cancel clicked.");
    }
}

Unable to understand where i am making mistake, implementation regarding UiHandlers is same as told in the above mentioned tutorial's link.

1

1 Answers

0
votes
 UiHandlers is not generic; it cannot be parameterized with arguments 

As I see your handler interface, you have passed AUiHandlers type. I don't understand the package structure of UiHandlers . it should be com.gwtplatform.mvp.client.UiHandlers.

Please check import of it.

Update:

Remove private static AViewUiBinder uiBinder = GWT.create(AViewUiBinder.class);

and Pass as constructor argument

 @Inject
    public AssetView(AViewUiBinder uiBinder) {
        widget = uiBinder.createAndBindUi(this);
    }