On Martes 21 Febrero 2012 18:08:14 DrJ escribió:
I have the same problem.
I've "solved" it checking in the event handling methods on* if the presenter it's visible, instead of adding handlers/unbinding the presenter, but I don't thinks it's the best solution.
Regards
It is not a bug, this is the intended behavior, since a presenter that isn't show could be interested to updated itself even if it's not show so that the user can be able to see the updates we he comes back.
What kind of events are they? You can check "if visible", but I need to think a little bit about a clean way to do that.
In my use case I unbind a pretty big PresenterWidget with some hundred child
controls so I think it's appropiate.
But... talking about PresenterWidgets attached to events-
When I create the PW, in it's onBind method I use to do:
addRegisteredHandler( ... )
The problem is that when I hide it and later create it again then the PW gets
registered twice and the event handlers are executed two, three, etc, times. I
can unregister the event handlers in the onHide method, but if you say:
> You should never call unbind in onHide and unless you have heavy objects
> that you want to destroy, onHide and onUnbind are not useful.
What should I do to not have the event handlers registered again?
Regards
Any event handler should be initialised here rather than in the constructor. Also, it is good practice to perform any costly initialisation here.
Handlers registered by calling registerHandler(HandlerRegistration) will be removed when unbinding. Any other initialisation that takes place here (or as a side-effect of what is done here) should be taken down in onUnbind().
This method will never be invoked more then once, or if it is, the second time will necessarily be preceded by an invocation of onUnbind().
But on PresenterWidgets its called every time the PW is created, so its
registered each time, at least when using guice Providers and factories mad by
GinFactoryModuleBuilder
regards