GWT 锚定放置?

发布于 2024-10-20 22:30:19 字数 178 浏览 2 评论 0原文

在 GWT 2.1+ 应用程序中,如何生成指向外部消费地点的链接?

例如,假设我想创建一个指向 Place1 的链接。对于内部消耗,我可以执行 presenter.goTo(new Place1("token"))。我怎样才能将其变成用户可以粘贴到浏览器中的锚点或某种链接?

In a GWT 2.1+ app, how can I generate a link to a place for external consumption?

For instance, say I want to create a link to Place1. For internal consumption I could do presenter.goTo(new Place1("token")). How can I make this into an Anchor or some sort of link that users can paste into their browser?

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

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

发布评论

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

评论(4

酷遇一生 2024-10-27 22:30:19

我会这样做:

final Place1 place = new Place1("token");
Anchor anchor = new Anchor("go to place 1", "#" + placeHistoryMapper.getToken(place));
anchor.addClickHandler(new ClickHandler() {
  public void onClick(ClickEvent event) {
    placeController.goTo(place);
    event.preventDefault();
  }
});

Here's how I would do:

final Place1 place = new Place1("token");
Anchor anchor = new Anchor("go to place 1", "#" + placeHistoryMapper.getToken(place));
anchor.addClickHandler(new ClickHandler() {
  public void onClick(ClickEvent event) {
    placeController.goTo(place);
    event.preventDefault();
  }
});
一曲爱恨情仇 2024-10-27 22:30:19

据我所知,因为我自己是 GWT 新手,如果您使用 Hyperlink 而不是 Anchor,则无需编写事件处理程序。它会将您重定向到该地点并自动处理历史记录。

As far as I know as i am new to GWT myself, if you use Hyperlink instead of Anchor you will not have to write the event handler. It will redirect you to the place and handle the history stuff automatically.

东风软 2024-10-27 22:30:19

您可以使用 PlaceHistoryMapper 将地点转换为标记字符串。请参阅https://developers.google.com/web-toolkit/doc/latest/ DevGuideMvpActivitiesAndPlaces 了解有关如何在 GWT 中实现 MVP 设计的详细信息。

final YourImplementationOfPlaceHistoryMapper placeHistoryMapper = GWT.create(YourImplementationOfPlaceHistoryMapper.class);

final Hyperlink link = new Hyperlink("A Link To A Place", placeHistoryMapper.getToken(new YourNewPlace()));

You can convert a place to a token string using the PlaceHistoryMapper. See https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces for details on how to implement the MVP design in GWT.

final YourImplementationOfPlaceHistoryMapper placeHistoryMapper = GWT.create(YourImplementationOfPlaceHistoryMapper.class);

final Hyperlink link = new Hyperlink("A Link To A Place", placeHistoryMapper.getToken(new YourNewPlace()));
┈┾☆殇 2024-10-27 22:30:19

如果您已经将令牌映射到某个位置,只需创建一个其 href 属性等于该令牌的锚点即可。

Anchor anchor = new Anchor("go to place1 ", "token");

If you have already mapped the token to a place, simply create an anchor with the href property equals to the token.

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