Messing with the PlaceManager during Presenter binding

23 views
Skip to first unread message

Manu Botija

unread,
Jan 30, 2014, 6:50:43 PM1/30/14
to gwt-pl...@googlegroups.com
This post is to understand a bug that I recently was able to fix in my code...

I have a Presenter which is the following place /mr/{id}/{tab}

- id, is the ID of the main object defining the Presenter
- {tab}, determines the content I show in one of the panels of my presenter (I don't use TabPresenter because it does not fit my needs 100%)

The Presenter has 3 links that I also use to navigate through the different {tab} elements. Those three links are initialized with this function which resides in the Presenter's view:


        public void configureNavLinks(){

               bodyNavLink.setTargetHistoryToken(challengeUtil.generateToken(ChallengeTabType.VIEW));

               ideasNavLink.setTargetHistoryToken(challengeUtil.generateToken(ChallengeTabType.IDEAS));

               updatesNavLink.setTargetHistoryToken(challengeUtil.generateToken(ChallengeTabType.UPDATES));

       }



To generate the Token for each link, I make use of the PlaceManager twice (first to get the current place, second to build the HistoryToken):

        public String generateToken(ChallengeTabType type){

               PlaceRequest request = generateRelativePlaceRequest(type);    

                return placeManager.buildHistoryToken(request);

       }

        private PlaceRequest generateRelativePlaceRequest (ChallengeTabType type){

             return new PlaceRequest.Builder(placeManager.getCurrentPlaceRequest())

         .with("tab", type.getToken())

          .build();

       }



Now, originally, and since the links have to be initialized once, I placed configureNavLinks() in the View's constructor. 

This messes up completely the PlaceManager. As a result the placeHierarchy of PlaceManager is changed to the last link that I setup in my constructor. As a consequence, whenever I was trying to manually enter the full URL to a tab (for ex myapp.com/#/mr/123123/view, the placeManager ended always showing the tab of the latest link that I initialize in my configureNavLinks() function . I don't understand why, don't ask me why. The same happens if instead of placing configureNavLinks() in the View's constructor, I place it in the Presenter's onBind() method (through getView().)

The problem goes away when I use configureNavLinks() in something like onReveal() or onReset().

I am posting this here in case in the future it will help others. But if in addition, someone can explain me the reasoning behind this issue, I would be grateful.



Christian Goudreau

unread,
Jan 31, 2014, 4:40:09 PM1/31/14
to gwt-pl...@googlegroups.com
(I don't use TabPresenter because it does not fit my needs 100%)
Which is fine, most of the time it is a lot more simpler to listen to navigation event and use pure css to create your tab in a completely decoupled manner.

As for you answer, it seems to be linked to the fact that using the view constructor or onBind(), elements are not at that moment in the dom, the you run into a race condition.

Using onReveal and/or onReset, makes sure that every element of your view are in the DOM.

Try using an attach handler in your view, you'll see if I was right or wrong about this assumption. BUT, as far as the mvp pattern is concerned, the view shouldn't know about the placemanager and the right place to do that work is in your presenter.

I hope it shed a little bit of light. 


--
You received this message because you are subscribed to the Google Groups "GWTP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gwt-platform...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Christian Goudreau | CEO - Président
M: 1.877.635.1585 | S: christian.goudreau

Manu Botija

unread,
Feb 3, 2014, 4:58:54 AM2/3/14
to gwt-pl...@googlegroups.com
Hi Christian,

Yes, your message is quite helpful. And thanks for pointing to me the MVP pattern inconsistency. I am using an util class to generate the history tokens, but I should not call that class from the view, I should do it from the presenter and pass the info down to the view. It is more biolerplate code work to do but I guess it is the right thing to do. I will address that.

Cheers,
Manuel


--
You received this message because you are subscribed to a topic in the Google Groups "GWTP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gwt-platform/AImtCkw1kuU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gwt-platform...@googlegroups.com.

Christian Goudreau

unread,
Feb 5, 2014, 8:52:17 AM2/5/14
to gwt-pl...@googlegroups.com
You're welcome!
Reply all
Reply to author
Forward
0 new messages