簡體   English   中英

GWT MVP示例項目:無法調用演示者的方法

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

我正在使用GWT mvp示例項目創建自己的mvp應用程序。

我幾乎做了他們所做的事情,即定義了Presenter接口,然后定義了不同的Presenter類。

在他們的代碼中,他們正在其中一個View類中執行以下操作:

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

演示者通過以下方法注入:

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

}

好吧...事實證明,由於IPresenter是一個接口,我無法調用onLoginButtonClicked。 他們在代碼中做到這一點。 這應該如何工作?

您必須具有一個為該視圖實現Presenter接口的類。

就像是:

public class MyActivity extends AbstractActivity implements MyView.Presenter {}

然后,您有一個View類:

public interface MyView extends IsWidget {

    public interface Presenter {
        void onLoginButtonClicked();
    }

    void setPresenter(Presenter listener);
}

最后,您將實現此視圖:

public class MyViewImpl extends Composite implements MyView {}

注意:我強烈建議您使用“ 活動和地點”模式。 它為具有多個視圖的任何應用程序提供了良好的結構,並增加了良好的歷史記錄支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM