Hyperlink with PlaceHistoryMapper

176 views
Skip to first unread message

Cristian Rinaldi

unread,
Jan 13, 2012, 9:22:36 AM1/13/12
to google-we...@googlegroups.com
I have a problem with Hyperlink, this code is part of my View:

<g:Hyperlink ui:field = "newTaskLink" targetHistoryToken='newTask'>New Task</g:Hyperlink>

When I made a click over link, the URL change to: 


But PlaceHistoryMapper never is called, therefore, my ActivityMapper never know the change of place (#newtask) and I can never start the activity.

Other places that do not use hyperlink going well.

Some code:

AppPlaceHistoryMapper
@WithTokenizers({DefaultPlace.Tokenizer.class, NewTaskPlace.Tokenizer.class}) 
public interface AppPlaceHistoryMapper extends PlaceHistoryMapper {
}


NewTaskPlace
public class NewTaskPlace extends Place {

    public static class Tokenizer implements PlaceTokenizer<NewTaskPlace> {

        @Override
        public NewTaskPlace getPlace(String token) {
            return new NewTaskPlace();
        }

        @Override
        public String getToken(NewTaskPlace place) {
            return "newTask";
        }
    }
}

Part of CenterActivityMapper
--------
@Override
    public Activity getActivity(Place place) {

        if (place instanceof DefaultPlace){
            HomeActivity activity = homeActivity.get();
            return activity;
        } else if (place instanceof NewTaskPlace ){
            TaskActivity activity = taskActivity.get();
            return activity;

        }
        return null;
    }


Thanks!!!!

Jens

unread,
Jan 13, 2012, 10:02:36 AM1/13/12
to google-we...@googlegroups.com
Your targetHistoryToken has to be "NewTaskPlace:newTask". 

By default GWT uses <prefix>:<token> as history token. The prefix can be configured by using the @Prefix annotation on your PlaceTokenizer class. If you don't do that, GWT will use the Place's class name as prefix.

If you use the @Prefix annotation keep in mind that the prefix must be unique.

-- J.

Cristian Rinaldi

unread,
Jan 13, 2012, 10:30:56 AM1/13/12
to google-we...@googlegroups.com
Jim thank you very much!!
When you are immersed in many lines of code ignores things simple.

Regards.

A.U.S Cristian Rinaldi

Teléfono Móvil: (0342) 155 238 083

www.logikas.com

Lisandro de la Torre 2643 Of 5 - 3000 - Santa Fe

Teléfono Fijo: (0342) 483 5138







2012/1/13 Jens <jens.ne...@gmail.com>

--
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/-/LhzBZoVp9J4J.

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.

Thomas Broyer

unread,
Jan 14, 2012, 6:42:20 AM1/14/12
to google-we...@googlegroups.com, cristian...@logikas.com
If I were you, I'd use the PlaceHistoryMapper to build the token out of the target Place; and I would even use an Anchor with ClickHandler and PlaceController.goTo instead of an Hyperlink.

Cristian Rinaldi

unread,
Jan 16, 2012, 9:10:33 AM1/16/12
to google-we...@googlegroups.com
Thanks thomas!!! 
But as an internal navigation menu, I think it is best to use Hyperlink.
A.U.S Cristian Rinaldi

Teléfono Móvil: (0342) 155 238 083

www.logikas.com

Lisandro de la Torre 2643 Of 5 - 3000 - Santa Fe

Teléfono Fijo: (0342) 483 5138







2012/1/14 Thomas Broyer <t.br...@gmail.com>

Thomas Broyer

unread,
Jan 16, 2012, 2:48:29 PM1/16/12
to google-we...@googlegroups.com, cristian...@logikas.com


On Monday, January 16, 2012 3:10:33 PM UTC+1, Cristian Rinaldi wrote:
Thanks thomas!!! 
But as an internal navigation menu, I think it is best to use Hyperlink.

Let me disagree.

The only (the one and only) difference is that with Hyperlink you update the history token and let the PlaceHistoryHandler handle the change and call the PlaceController with the deserialized Place; instead of changing Place which will trigger the PlaceHistoryHandler to update the history token.
What it means in practice is that the PlaceChangeRequest event is dispatched *after* the history token has changed when using an Hyperlink (which uses Histoy.newItem), but before it when using PlaceController.goTo; so if an activity returns a non-null value from its mayStop and the  user cancels the navigation, the history token has already been changed.

It's best to always use PlaceController.goTo, even if that means making your own "PlaceHyperlink" widget (feeding it with the Place to go to and a PlaceHistoryMapper –to build the link's href out of the Place, in case the user wants to "open in new tab"–).

Cristian Rinaldi

unread,
Jan 16, 2012, 3:45:01 PM1/16/12
to google-we...@googlegroups.com
Thanks Thomas.

Of course you're right with the theme of myStop, thanks for the clarification.


A.U.S Cristian Rinaldi

Teléfono Móvil: (0342) 155 238 083

www.logikas.com

Lisandro de la Torre 2643 Of 5 - 3000 - Santa Fe

Teléfono Fijo: (0342) 483 5138







2012/1/16 Thomas Broyer <t.br...@gmail.com>
Reply all
Reply to author
Forward
0 new messages