简体   繁体   English

GWT MVP示例项目:无法调用演示者的方法

[英]GWT mvp sample project: cannot call method of presenter

I am using the GWT mvp sample project to create my own mvp application. 我正在使用GWT mvp示例项目创建自己的mvp应用程序。

I pretty much did what they did, ie defined a Presenter interface and then different presenter classes. 我几乎做了他们所做的事情,即定义了Presenter接口,然后定义了不同的Presenter类。

In their code, they are doing something like this in one of the View classes: 在他们的代码中,他们正在其中一个View类中执行以下操作:

@UiHandler("loginButton")
void onClick(ClickEvent e) {
    if (presenter != null) {
        presenter.onLoginButtonClicked();
    }
}

The presenter is injected through this method: 演示者通过以下方法注入:

public void setPresenter(IPresenter presenter) {
    this.presenter = presenter;

}

Well duh... turns out, I am unable to call the onLoginButtonClicked, since IPresenter is an interface. 好吧...事实证明,由于IPresenter是一个接口,我无法调用onLoginButtonClicked。 They do that in their code. 他们在代码中做到这一点。 How is this supposed to work? 这应该如何工作?

You have to have a class that implements Presenter interface for this view. 您必须具有一个为该视图实现Presenter接口的类。

Something like: 就像是:

public class MyActivity extends AbstractActivity implements MyView.Presenter {}

Then you have a View class: 然后,您有一个View类:

public interface MyView extends IsWidget {

    public interface Presenter {
        void onLoginButtonClicked();
    }

    void setPresenter(Presenter listener);
}

Finally, you will have an implementation of this view: 最后,您将实现此视图:

public class MyViewImpl extends Composite implements MyView {}

NB: I strongly recommend Activities and Places pattern. 注意:我强烈建议您使用“ 活动和地点”模式。 It gives a good structure for any app with more than one view, and adds good history support. 它为具有多个视图的任何应用程序提供了良好的结构,并增加了良好的历史记录支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM