Reputation: 1682
I am using the GWT mvp sample project to create my own mvp application.
I pretty much did what they did, i. e. defined a Presenter
interface and then different presenter classes.
In their code, they are doing something like this in one of the View
classes:
@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. They do that in their code. How is this supposed to work?
Upvotes: 0
Views: 221
Reputation: 41089
You have to have a class that implements Presenter interface for this view.
Something like:
public class MyActivity extends AbstractActivity implements MyView.Presenter {}
Then you have a View class:
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.
Upvotes: 2