I am new at GWT, but I have working on the MVP tutorial and have
encountered some problems:
from my EntryPoint class:
public void onModuleLoad() {
HandlerManager eventBus = new HandlerManager(null);
AppController appController = new AppController(eventBus);
appController.go(RootLayoutPanel.get());
}
in the AppController:
public AppController(HandlerManager eventBus){
this.eventBus = eventBus;
bind();
}
private void bind() {
eventBus.addHandler(LogOutEvent.TYPE, new LogOutEventHandler() {
@Override
public void onLogOut(LogOutEvent event) {
Window.alert("yes!"); //does not work :-(
}
});
eventBus.addHandler(LoginEvent.TYPE, new LoginEventHandler() {
@Override
public void onLogin(LoginEvent event) {
handleLogin(event.getUser()); // does work ?!
}
});
}
@Override
public void go(final HasWidgets container) {
this.container = container;
LoginView loginView = new LoginView();
presenter = new LoginPresenter(eventBus, rpcLoginService,
loginView);
loginView.setPresenter(presenter);
presenter.go(container);
}
private void handleLogin(User user) {
LogoutView logoutView = new LogoutView();
presenter = new LogoutPresenter(eventBus, rpcLogoutService,
logoutView, user);
logoutView.setPresenter(presenter);
presenter.go(container);
}
private void handleLogout(){
Window.alert("hej");
LoginView loginView = new LoginView();
presenter = new LoginPresenter(eventBus, rpcLoginService,
loginView);
loginView.setPresenter(presenter);
presenter.go(container);
}
Please note above that the login handler is registered and works
flawlessly!
Also note that I've got two presenters: LoginPresenter,
LogOutPresenter. And they are
basically the same; they get informed by a view that a button has been
clicked and do a
RPC (which works).
in LogOutPresenter:
public void onLogOutButtonClicked(){
rpcService.logoutNow(user, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
LogOutEvent logout = new LogOutEvent();
eventBus.fireEvent(logout); //does not do
anything!
Window.alert("" +
eventBus.isEventHandled(LogOutEvent.TYPE)); //
this yields true?!
}
@Override
public void onFailure(Throwable caught) {
if(caught instanceof UserLoginException)
Window.alert("exception occured");
}
});
}
If I debug in the onSuccess method above and step into
eventBus.fireEvent(logout), I get
to a place where I see the handler list is empty! even though the
event is registered!
Any Ideas?
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.