没有冒号 (:) 的地名?

发布于 2024-12-20 16:50:10 字数 341 浏览 2 评论 0原文

这里仍然是一个 GWT 菜鸟,但使用 Google

我知道 Place 的“URL 由 Place 的简单类名(如“HelloPlace”)组成,后跟冒号 (:) 和 PlaceTokenizer 返回的令牌。

当我没有冒号时,我可以以某种方式删除冒号吗发送令牌?

例如,当我需要使用 PersonId=2 时,我可以使用“#editPerson:2”这样的 URL,但是当我只想呈现一个空白的 Person 表单时呢? ?在那种情况下我会更喜欢使用“#addPersonForm”而不是“#addPersonForm:”

任何建议(甚至更好的代码建议)将不胜感激!

Still a bit of a GWT noob here but making progress using Activities and Places as described by Google here.

I understand that a Place's "URL consists of the Place's simple class name (like "HelloPlace") followed by a colon (:) and the token returned by the PlaceTokenizer.

Can I somehow remove the colon when I don't have a token to send?

For example, I'm fine with a URL like this "#editPerson:2" when I need to work with PersonId=2. But what about when I just want to present a blank Person form? In that case I would prefer to use "#addPersonForm" rather than "#addPersonForm:"

Any suggestions (even better code suggestions) would be most appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我喜欢麦丽素 2024-12-27 16:50:10

您可以按照 Boris_siroB 的建议提供自己的 PlaceHistoryMapper (不使用生成器),或者您可以在具有空前缀的 PlaceTokenizer 中执行此操作:使用空前缀,不会有冒号,并且标记生成器可以执行任何操作你想要的。如果你完全不同的地方,让它成为 Place 的分词器,所以它也是 getToken 的“包罗万象”。这样你就可以保留带有前缀、PlaceTokenizers 和 WithTokenizers 的一代的所有优点(如果你想利用它们)

You can provide your own PlaceHistoryMapper (without using the generator) as already suggested by Boris_siroB, or you can do it within a PlaceTokenizer with an empty prefix: with an empty prefix, there won't be a colon, and the tokenizer can do whatever you want. If you totally distinct places, make it a tokenizer of Place, so it's also the "catchall" for getToken. That way you can keep all the advantages of the generation with prefixes, PlaceTokenizers and WithTokenizers (if you want to take advantage of them)

柠栀 2024-12-27 16:50:10

要完全控制 URL 哈希(即从地点生成您自己的令牌并将这些令牌映射回地点),您可以实现自己的历史映射器(一个实现 PlaceHistoryMapper 接口)。

public class MyPlaceHistoryMapper implements PlaceHistoryMapper {

   @Override
   public Place getPlace(String token) {
        // parse tokens and create Places here  
   }

   @Override
   public String getToken(Place place) {
        // examine Places and compose tokens here
   }
}

然后,在您的入口点类中,您可以将行:替换

AppPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);

为:

PlaceHistoryMapper appHistoryMapper = new MyPlaceHistoryMapper();

就是这样。您的 URL 哈希不再需要基于类名或使用 : 分隔符。

To take full control of the URL hash (that is to generate your own tokens from Places and map these tokens back to Places) you can implement your own history mapper (a class implementing the PlaceHistoryMapper interface).

public class MyPlaceHistoryMapper implements PlaceHistoryMapper {

   @Override
   public Place getPlace(String token) {
        // parse tokens and create Places here  
   }

   @Override
   public String getToken(Place place) {
        // examine Places and compose tokens here
   }
}

In your entry point class you'd then replace the line:

AppPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);

with:

PlaceHistoryMapper appHistoryMapper = new MyPlaceHistoryMapper();

That's it. Your URL hashes no longer need to be class name-based or to use the : delimiter.

在巴黎塔顶看东京樱花 2024-12-27 16:50:10

我正在使用名为 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 "";
        }

    }
}

I'm using a PlaceHistoryMapper decorator named PlaceHistoryMapperWithoutColon.

Usage :

final PlaceHistoryMapper historyMapper0 = GWT
                .create(PlaceHistoryMapperImpl.class);

final PlaceHistoryMapper historyMapper = new PlaceHistoryMapperWithoutColon(historyMapper0);

Decorator source :

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;
    }

}

Decorated source example :

@WithTokenizers({ FirstPlace.Tokenizer.class, SecondPlace.Tokenizer.class })
public interface PlaceHistoryMapperImpl extends PlaceHistoryMapper {

}

Place source example :

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 "";
        }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文