gwtactivity-managergwt-activities

ActivityMapper, dealing with regions which don't change a lot


I'm new with GWT and recently I've added Actvivities, Places and ActivityMappers to my code. I have one ActivityManager-ActivityMapper per each region. Regions like the header or the menu dont't change a lot so I have to write a lot of boilerplate code in the ActivityMapper for load the same Presenter every time but with a different constructor. For every possible Place I have to write another constructor for the Presenter in order to take the instance given by the ActivityMapper. There's any way to do that easier? Moreover, I'm not happy with the idea of creating a new Presenter every time that we move to a new place(even if you are going to load the same Presenter). In fact I have a big problem with that, cause my activities never die and they keep receiving events.


Solution

  • When an ActivityMapper returns the exact same Activity instance (reference equality, i.e. ==, not equals()) as previously, then the activity is not restarted, and the region is not touched. This is a deliberate optimization for those cases of regions that don't change often (e.g. headers or menus, or a master region in a master-detail setup). This is also the reason for the CachingActivityMapper (and FilteredActivityMapper, specifically designed to be used with the CachingActivityMapper in a master-detail setup)

    In your case, it seems like you're imposing a rule to yourself that makes it hard for you to take advantage of this optimization: you're passing the current place to your activity's constructor, for no apparent reason.