GWT anchor in place?

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

For example, let's say I want to create a link to Place1. For domestic consumption, I could do presenter.goTo(new Place1("token")). How can I do this in Anchoror some link that users can embed in their browser?

+5
source share
5 answers

Here is 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();
  }
});
+5
source

As far as I know, since I'm new to GWT myself, if you use Hyperlink instead of Anchor, you will not need to write an event handler. It redirects you to the place and automatically processes the story.

+2
source

, PlaceHistoryMapper. , MVP GWT, . https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.

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

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

If you have already matched the token with the place, just create a binding with the href property equal to the token.

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

MyView.ui.xml:

<g:InlineHyperlink ui:field="link">Link</g:InlineHyperlink>

MyView.java:

@UiField InlineHyperlink link;

public MyView() {
    // ...
    link.setTargetHistoryToken(getPlaceHistoryMapper().
            getToken(new Place1("token")));
    // ...
}
0
source

All Articles