Wednesday, February 15, 2012

Re: Newbie help with HandleManager (eventbus) not registrering handler for event in MVP tutorial (modified)

Thanks for the reply Chris!

Meanwhile I figured out the problem; it was a stub implementation by
eclipse that I've forgotten in the LogOutEvent class...

On Feb 15, 6:08 am, Chris Price <pric...@gmail.com> wrote:
> I can't see how it's happening in your case (either there's more
> relevant code or it's very early in the morning!) but I've previously
> come across a similar problem. The SimpleEventBus, on which
> HandlerManager is based, uses deferred methods to only apply changes
> to the handler lists after the current round of events have fired [1].
> i.e. if you are currently in a handler, add a handler and then
> immediately fire that event, your handler won't be called (ever).
>
> [1]http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/...
>
> Chris
>
> On Tue, Feb 14, 2012 at 9:57 AM, claus.jespep...@googlemail.com
>
>
>
>
>
>
>
> <claus.jespep...@googlemail.com> wrote:
> > 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 google-web-toolkit@googlegroups.com.
> > To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/google-web-toolkit?hl=en.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate