我使用了一個名爲PlaceHistoryMapperWithoutColon的PlaceHistoryMapper裝飾器。
用法:
final PlaceHistoryMapper historyMapper0 = GWT
.create(PlaceHistoryMapperImpl.class);
final PlaceHistoryMapper historyMapper = new PlaceHistoryMapperWithoutColon(historyMapper0);
裝飾源:
public class PlaceHistoryMapperWithoutColon implements PlaceHistoryMapper {
private static final String COLON = ":";
private PlaceHistoryMapper placeHistoryMapper;
public PlaceHistoryMapperWithoutColon(PlaceHistoryMapper placeHistoryMapper) {
this.placeHistoryMapper = placeHistoryMapper;
}
@Override
public Place getPlace(String token) {
if (token != null && !token.endsWith(COLON)) {
token = token.concat(COLON);
}
return placeHistoryMapper.getPlace(token);
}
@Override
public String getToken(Place place) {
String token = placeHistoryMapper.getToken(place);
if (token != null && token.endsWith(COLON)) {
token = token.substring(0, token.length() - 1);
}
return token;
}
}
裝飾源例如:
@WithTokenizers({ FirstPlace.Tokenizer.class, SecondPlace.Tokenizer.class })
public interface PlaceHistoryMapperImpl extends PlaceHistoryMapper {
}
地點源例如:
public final class FirstPlace extends Place {
@Prefix("first")
public static class Tokenizer implements PlaceTokenizer<FirstPlace> {
@Override
public NetworkInfosPlace getPlace(String token) {
return new FirstPlace();
}
@Override
public String getToken(FirstPlace place) {
return "";
}
}
}
這是來自doc:'你的應用中的許多地方可能不會保存任何狀態到URL,所以他們可以擴展一個BasicPlace,它聲明一個返回null標記的PlaceTokenizer'你是否嘗試創建PlaceTokenizer,你的添加人形式的空令牌? – Strelok
感謝您的回覆。如果我從getToken(PlaceName地方)返回null,那麼我最終會得到如下的URL:「#addPersonForm:null」。我錯過了什麼(可能:)? – Justin