i have an activity that needs another class’ service to retrieve some data (“DataClass”). This data class can be called to fetch data and will fire an event on success.
the first time that activity need the data is on “start” – to resolve the state brought by the current place and update the view accordingly.
the problem is that the activities onDataEvent method isn’t called the first time but on alle subsequent events. I checked the event’s handlers. On time the first event is fired the activity is registered with this event. I also tried to register the event withing constructor but this changes nothing.
So how to register an activity for an event, trigger and react on it within the start method? Or how to generally implement such an use case.
EDIT
in meantime i tried to implement it like here but with no success.
here is the code of the start method:
@Override
public final void start(final AcceptsOneWidget panel, final com.google.gwt.event.shared.EventBus eventBus) {
this.eb = new ResettableEventBus(eventBus);
if (!(pc.getWhere() instanceof DynamicTablePlace)) {
throw new IllegalStateException(CreateDynamicTableActivity.class.getName() + " should only be called on "
+ DynamicTablePlace.class.getName());
}
view.setPresenter(this);
this.eb.addHandler(DynamicTableHashResolvedEvent.TYPE, this);
stateResolver.resolveState(((DynamicTablePlace) pc.getWhere()).getTablehash(), eb); //this is triggering the event
panel.setWidget(view);
}
the onDynamicTableHashResolved(DynamicTableHashResolvedEvent event) method isn’t called the first time but on all subsequent events.
in google groups someone pointed me on the problem. I already stumbled across this kind of problem. The problem is: if the browser handles some events (the activities start method is called upon a place change event) and you register another event within this process and trigger the event just registered it will not work – the registration is not “complete” at this moment.
The solution is simple: trigger the event “deferred” in my code:
The problem is: this breaks test-ability (without gwt test case) of this activity.
from Thomas Broyer: if scheduler is injected i can normally test and there is a StubScheduler provided for use in test. in my case i created a mock for scheduler that just executes the command – in my case only scheduleFinally(ScheduledCommand cmd) must be implemented.