3

in my app i have a relative complex activity/place. Resolving the state (from history token to model) on start of activity causes some server interactions. On user interactions the activity only updates the necessary parts of the model and therefore safes some server interactions - the activity/model has an inner state.

Is there a way to reflect the state in browser history without (re)starting the activity? (History.newItem(token) also causes start of activity)

UPDATE Chris' solution "nearly" works but another problem rose: in my ui i have a reset-button (a link to the place with empty token). If i click around the ui the token is updated fine but now the reset button doesn't work. gwt thinks it is in the same place and so it ignores the reset click. Before this the problem was nearly the same: the token and place didn't change and so the reset button didn't work either. GWT logs this as "Asked to return to the same place"

So is there a way to let gwt restart the activity regardless of place equivalence?

dermoritz
  • 12,519
  • 25
  • 97
  • 185

2 Answers2

3

Go to a new place, but have your ActivityMapper return the same activity instance. That way, the activity is not restarted.
You have to find a mean of updating the activity when the place changes from some other mean though (e.g. browser history). See GWT MVP updating Activity state on Place change for instance.

Community
  • 1
  • 1
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • 1
    thx thomas - i allways thougt "start" is allways called but the constructor is only called if i return "new activity". the problem is i have to distinguish between user entered/altered url (restart activity) and user interacted with interface (only update the token). – dermoritz Aug 23 '12 at 12:16
  • 1
    after some research and try and error i understand. and indeed the fact that activity isn't restarted if mapper returns same activity is the crux. the reset button isn't working either. but now i have all infos in place. – dermoritz Aug 23 '12 at 13:53
2

There is a semi-solution, and although I don't want to recommend it, I'd like to add it here - just to warn against the drawbacks of this solution:

You could add tokens to the History without firing an event by calling History.newItem(token, false).

This is a semi-solution, because:

  • It works correctly (as long as you build your tokens correctly).
  • A part of the performance problem is also solved: The activity won't be re-started when adding the token to the history.
  • However, if the user goes back and forward through the history, the performance problem would still be there (because then, the events will be fired again).
Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
  • thx - that is exactly what i want: no reastart on user interactions but restart on forward/back and url entered. – dermoritz Aug 23 '12 at 12:17
  • @dermoritz: Please be really careful, if you actually want to use this. Note especially, that `PlaceController.getWhere()` will not return an updated Place! – Chris Lercher Aug 23 '12 at 12:44
  • thats right, see my update. now the state is correctly reflected but my reset-link still isn't working. – dermoritz Aug 23 '12 at 13:09
  • 1
    @dermoritz: By using this solution, you're changing the concept of Place equivalence, and that must be reflected in their equals() implementations: Use the default Object.equals() implementation for this kind of Place concept. This is legal. The drawback (to mention it again) is, that you will always create a new Activity when `PlaceController.goTo(...)` is called - but this is the only way to do it within this solution. – Chris Lercher Aug 23 '12 at 13:19
  • 1
    thx, i thought regardless of place equivalence always the mappers getActivity is called. And place equivalence is used for "FilteredActivityMapper". some month ago i used FilteredActivityMapper and CachingActivityMapper to reuse the activity if place is equivalent, but this seem to be bullshit - the place equivalence filter seem to be always on?! – dermoritz Aug 23 '12 at 13:25