Activity how to react on event that is triggered in start-method

64 views
Skip to first unread message

tanteanni

unread,
Apr 24, 2012, 9:49:11 AM4/24/12
to google-we...@googlegroups.com
i have an activity that needs another class to resolve the state (ids to real objects) brought by current place. this class' "getData(StateObject)" is called within start-method right after registering for the class' gotData-event. But the activitie's onGotData-data method isn't called the first time. If the activity calls getData after the start method all works fine.
i have the feeling that this can't work but how to get it working? The data class need an object provided by a special kind of place (the same place as the activity starts on).

Chris Price

unread,
Apr 24, 2012, 1:19:28 PM4/24/12
to google-we...@googlegroups.com

Does your data fetch include the event bus in some way? If so you may be running into the problem that handler changes (adds/removes) are only applied after the current event has completed. In this case that event would be the place change eventually calling the activity start.

Sorry for the lack of references, im not at a pc

On 24 Apr 2012 14:49, "tanteanni" <tant...@hotmail.com> wrote:
i have an activity that needs another class to resolve the state (ids to real objects) brought by current place. this class' "getData(StateObject)" is called within start-method right after registering for the class' gotData-event. But the activitie's onGotData-data method isn't called the first time. If the activity calls getData after the start method all works fine.
i have the feeling that this can't work but how to get it working? The data class need an object provided by a special kind of place (the same place as the activity starts on).

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

tanteanni

unread,
Apr 25, 2012, 2:11:35 AM4/25/12
to google-we...@googlegroups.com
i think this is not the problem. first i register for event then i fetch the data that triggers the event. here is the code of start method:

    @Override
    public final void start(final AcceptsOneWidget panel, final com.google.gwt.event.shared.EventBus eventBus) {
        this.eb = new ResettableEventBus(eventBus);
        view.setPresenter(this);
        this.eb.addHandler(DynamicTableHashResolvedEvent.TYPE, this);//handler registration
        stateResolver.resolveState(((DynamicTablePlace) pc.getWhere()).getTablehash(), eb);//triggers event
        panel.setWidget(view);
    }

the event triggered in start method will be received when next event is triggered - so after the start method i am one event too "late".


On Tuesday, 24 April 2012 19:19:28 UTC+2, Chris Price wrote:

Does your data fetch include the event bus in some way? If so you may be running into the problem that handler changes (adds/removes) are only applied after the current event has completed. In this case that event would be the place change eventually calling the activity start.

Sorry for the lack of references, im not at a pc

On 24 Apr 2012 14:49, "tanteanni" wrote:
i have an activity that needs another class to resolve the state (ids to real objects) brought by current place. this class' "getData(StateObject)" is called within start-method right after registering for the class' gotData-event. But the activitie's onGotData-data method isn't called the first time. If the activity calls getData after the start method all works fine.
i have the feeling that this can't work but how to get it working? The data class need an object provided by a special kind of place (the same place as the activity starts on).

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/6MNHc8yNbm0J.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

Chris Price

unread,
Apr 25, 2012, 2:21:58 AM4/25/12
to google-we...@googlegroups.com
Ah yes, the code you pasted exactly fits the problem I described. The
activity start method is called by the ActivityManager from within the
PlaceChangeEvent.Handler [1]. The SimpleEventBus, uses deferred
methods to only apply changes to the handler lists after the current
round of events have fired [2]. i.e. if you are currently in a
handler, add a handler and then immediately fire that event, your
handler won't be called.

[1] http://code.google.com/p/google-web-toolkit/source/browse/branches/2.1/bikeshed/src/com/google/gwt/app/place/ActivityManager.java?r=8009#85
[2] http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java#156

>>> To post to this group, send email to google-we...@googlegroups.com.


>>> To unsubscribe from this group, send email to

>>> google-web-tool...@googlegroups.com.


>>> For more options, visit this group at
>>> http://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 view this discussion on the web visit

> https://groups.google.com/d/msg/google-web-toolkit/-/BLVNKJReNVAJ.
>
> To post to this group, send email to google-we...@googlegroups.com.


> To unsubscribe from this group, send email to

> google-web-tool...@googlegroups.com.

tanteanni

unread,
Apr 25, 2012, 2:54:12 AM4/25/12
to google-we...@googlegroups.com

Thanks!
I understand (some time ago i had a similar problem but in my "main"-Class - it didn't react on first place change event)
but the solution is ugly:
...Scheduler.get().scheduleFinally(new ScheduledCommand()...

is there another way to get this working? i need the dataModel in start to restore the state given by place.


On Wednesday, 25 April 2012 08:21:58 UTC+2, Chris Price wrote:
Ah yes, the code you pasted exactly fits the problem I described. The
activity start method is called by the ActivityManager from within the
 PlaceChangeEvent.Handler [1]. The SimpleEventBus, uses deferred
methods to only apply changes to the handler lists after the current
round of events have fired [2]. i.e. if you are currently in a
handler, add a handler and then immediately fire that event, your
handler won't be called.

[1] http://code.google.com/p/google-web-toolkit/source/browse/branches/2.1/bikeshed/src/com/google/gwt/app/place/ActivityManager.java?r=8009#85
[2] http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java#156

>>> To post to this group, send email to google-web-toolkit@googlegroups.com.


>>> To unsubscribe from this group, send email to


>>> For more options, visit this group at
>>> http://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 view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/BLVNKJReNVAJ.
>

> To post to this group, send email to google-web-toolkit@googlegroups.com.


> To unsubscribe from this group, send email to

Chris Price

unread,
Apr 25, 2012, 3:11:22 AM4/25/12
to google-we...@googlegroups.com
I think your only two choices are to either avoid the event bus for
the async data call, or as you suggest with the Scheduler.
>> >>> google-we...@googlegroups.com.
>> >>> To unsubscribe from this group, send email to
>> >>> google-web-tool...@googlegroups.com.
>> >>> For more options, visit this group at
>> >>> http://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 view this discussion on the web visit
>> > https://groups.google.com/d/msg/google-web-toolkit/-/BLVNKJReNVAJ.
>> >
>> > To post to this group, send email to
>> > google-we...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > google-web-tool...@googlegroups.com.
>> > For more options, visit this group at
>> > http://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 view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/ttj2N8rpsIIJ.
>
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.

tanteanni

unread,
Apr 25, 2012, 4:07:45 AM4/25/12
to google-we...@googlegroups.com
Ok so either i use Scheduler and loose test ability or i refactor and use a delegate/handler as used in async-services, right? (no answer means yes :-))


On Wednesday, 25 April 2012 09:11:22 UTC+2, Chris Price wrote:
I think your only two choices are to either avoid the event bus for
the async data call, or as you suggest with the Scheduler.

>> >>> google-web-toolkit@googlegroups.com.
>> >>> To unsubscribe from this group, send email to
>> >>> google-web-toolkit+unsub...@googlegroups.com.
>> >>> For more options, visit this group at
>> >>> http://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 view this discussion on the web visit
>> > https://groups.google.com/d/msg/google-web-toolkit/-/BLVNKJReNVAJ.
>> >
>> > To post to this group, send email to
>> > google-web-toolkit@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > google-web-toolkit+unsub...@googlegroups.com.
>> > For more options, visit this group at
>> > http://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 view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/ttj2N8rpsIIJ.
>
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsub...@googlegroups.com.

Jens

unread,
Apr 25, 2012, 4:49:52 AM4/25/12
to google-we...@googlegroups.com
Instead of using the EventBus you could also use a Callback in your StateResolver. Seems to me that only the class that calls stateResolver.resolve() is interested in the result, so there isn't a real need for using an application wide event bus.

stateResolver.resolveState(...., new Callback() {
  void onSuccess() {
    //call method that handles the state
   }
});

Or you implement the Callback interface directly in your Activity (but then I would rename it to StateResolverPeer.stateResolved(T state) or something like that) and then simply call stateResolver.resolveState(...., this).

If there is a 1:1 relation I would not use event bus in most cases.

-- J.

tanteanni

unread,
Apr 25, 2012, 5:00:13 AM4/25/12
to google-we...@googlegroups.com
you are right jens my first solution was a local eventbus - as you see my stateresolver takes an EventBus as argument - but this didn't work either. The current solution was copied from a gwt-example.

i used the solution with callback in two of my other activities. but my feeling isn't very good with it - i never use the eventbus given in start - why is there an eventbus?. because of this uncertainty i opened the other thread. I thought resolving a string /token to a model(that needs more than just call one service - probably i should refactor the services :-|) is a more usual use case.

So i guess i will refactor it and use a delegate to handle the callback.
Reply all
Reply to author
Forward
0 new messages