GWT real world token usage
So it looks like when using GWT Activities & Places, a token is always required. My question is, what token would you开发者_如何学Go provide for a page that would not typically have any additional arguments, such as a contact us page or place. Currently it looks like /#ContactUsPlace:token with a random token appended.
How do other developers use tokens.
Many thanks, Alex
Well, you can return empty token which will change url to /#ContactUsPlace: Also you can change prefix using @Prefix annotation to get ex. /#contactus:
If you want more controll then you can implement your own PlaceHistoryMapper, here is a simple example:
public class KatPlaceHistoryMapper implements PlaceHistoryMapper{
private static final String CONTACT = "contact";
private static final String ABOUT_US = "aboutUs";
@Override
public Place getPlace(String hash) {
if(token == null)
return new DefaultPlace();
else if(token.equals(CONTACT))
return new ContactPlace();
else if(token.equals(ABOUT_US))
return new AboutUsPlace();
else
return null;
}
@Override
public String getToken(Place place) {
if(place instanceof DefaultPlace)
return ""
else if(place instanceof ContactPlace)
return CONTACT;
else if(place instanceof AboutUsPlace)
return ABOUT_US;
else
return null;
}
}
Tokens returned/taken by above methods are actually whole hash-strings (not just the part after ':' ). In fact you get rid of tokens at all when using this approach. Writing own generator which would generate this class at compile-time seems to be a good choice. Also don't use PlaceHistoryMapperWithFactory, it gives you the same what you get with PlaceTokenizers.
some docs: http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html#PlaceHistoryMapper
精彩评论