GWT mvp 示例项目:无法调用演示者的方法
GWT mvp sample project: cannot call method of presenter
我正在使用 GWT mvp 示例项目创建我自己的 mvp 应用程序。
我几乎做了他们所做的,我。 e.定义了一个 Presenter
接口,然后是不同的演示者 类.
在他们的代码中,他们在 View
类:
之一中做类似的事情
@UiHandler("loginButton")
void onClick(ClickEvent e) {
if (presenter != null) {
presenter.onLoginButtonClicked();
}
}
presenter是通过这个方法注入的:
public void setPresenter(IPresenter presenter) {
this.presenter = presenter;
}
好吧...事实证明,我无法调用 onLoginButtonClicked,因为 IPresenter 是一个接口。他们在他们的代码中这样做。这应该如何工作?
您必须有一个 class 实现此视图的 Presenter 接口。
类似于:
public class MyActivity extends AbstractActivity implements MyView.Presenter {}
然后你有一个视图class:
public interface MyView extends IsWidget {
public interface Presenter {
void onLoginButtonClicked();
}
void setPresenter(Presenter listener);
}
最后,您将实现此视图:
public class MyViewImpl extends Composite implements MyView {}
注意:我强烈推荐 Activities and Places 模式。它为具有多个视图的任何应用程序提供了良好的结构,并添加了良好的历史记录支持。
我正在使用 GWT mvp 示例项目创建我自己的 mvp 应用程序。
我几乎做了他们所做的,我。 e.定义了一个 Presenter
接口,然后是不同的演示者 类.
在他们的代码中,他们在 View
类:
@UiHandler("loginButton")
void onClick(ClickEvent e) {
if (presenter != null) {
presenter.onLoginButtonClicked();
}
}
presenter是通过这个方法注入的:
public void setPresenter(IPresenter presenter) {
this.presenter = presenter;
}
好吧...事实证明,我无法调用 onLoginButtonClicked,因为 IPresenter 是一个接口。他们在他们的代码中这样做。这应该如何工作?
您必须有一个 class 实现此视图的 Presenter 接口。
类似于:
public class MyActivity extends AbstractActivity implements MyView.Presenter {}
然后你有一个视图class:
public interface MyView extends IsWidget {
public interface Presenter {
void onLoginButtonClicked();
}
void setPresenter(Presenter listener);
}
最后,您将实现此视图:
public class MyViewImpl extends Composite implements MyView {}
注意:我强烈推荐 Activities and Places 模式。它为具有多个视图的任何应用程序提供了良好的结构,并添加了良好的历史记录支持。