Page Links in GWT

From Zanecorpwiki

Jump to: navigation, search

One of GWT fundamental failings is the focus on "the app". There are issues with using GWT widgets within a page (which is the best way to do AJAX/modern web programming IMO). It is possible, however, to link plain old HTML to the GWT, and here I note how to do this with regular links:

First, give the link an ID:

<a id="theLink">

Second, create the action that does whatever you want the link to do:

class SomeCommand extends Command {
  public void execute() {
    Window.alert("You clicked the link!");
  }
}

Now, grab the element from the GWT setup code and wrap the link with an Anchor:

Anchor theLink = Anchor.wrap(Document.get().getElementById("theLink"));
  accountLink.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) { new SomeCommand().execute(); }
  });