I have a GWT Places/Activities web application. I use Anchor's click event to move user in a new "place", so there's no way user can open any "link" in a new window or tab. The question is - how do I make all these links real?
GWT Places/Activities - what should be used for navigation?
1k views Asked by Andrey Agibalov At
2
There are 2 answers
2
On
While using a Hyperlink (or InlineHyperlink) works, I'd rather use a ClickHandler on an Anchor, because if any activity returns a non-null value in mayStop the URL wouldn't have changed yet (whereas with a Hyperlink, it would have, even if the user chooses to cancel the navigation).
To set the target (href) on the Anchor, simply use your PlaceHistoryMapper. And to correctly handle the ctrl+click, middle-click and right-click, reuse the HyperlinkImpl:
Anchor anchor = new Anchor("text", "#" + placeHistoryMapper.getToken(targetPlace));
anchor.addClickHandler(new ClickHandler() {
private static final HyperlinkImpl IMPL = GWT.create(HyperlinkImpl.class);
@Override
public void onClick(ClickEvent event) {
if (IMPL.handleAsClick(event)) {
placeController.goTo(targetPlace);
event.preventDefault();
}
}
});
Maybe instead of using
Anchorand listening to theClickEventuseHyperlinkwith thetargetHistoryTokenset to the Place name.e.g.
<g:Hyperlink text="Home" targetHistoryToken="home" />