gwt

how to click anchor from code in GWT?


There is .click() method in Button class that you can .click() it from code not physically clicked it

Button b = new Button("b");
b.click();

How can I do that with Anchor ? I call rpc and I want to open it in a new tab onSuccess();

Anchor a = new ("a", "url", "_blank");

a.addClickHandler(new ClickHandler() {

   @Override
   public void onClick(ClickEvent event) {
           RPC(onSuccess()){
                  String href = rpc.getUrl();
                  a.setHref(href);  
                  a.click(); // How can I do that ?
           }

   }
});

Solution

  • You can use Window.Location.assign("url");

    Also this method can help you:

    public static native String getURL(String url)/*-{
            return $wnd.open(url, 'target=_blank')
        }-*/;