0

I want to call a Java method on a click of a button which is NOT created as usual in GWT but is created by using plain HTML.

Below is the sample code:-

private native void createHeaderSpanContents(Element element)/*-{

element.innerHTML='<button type="button" onclick="this.@ca.bell.nis.psp.client.gui.AbstractSearchResultGrid::hideColumns()()"></button>Identification';

}-*/;

public void hideColumns() {
    // Hide the columns
}

The above way of calling hideColumns() Java method from within JSNI does not work here. Please help!

Regards, -Trans.

Anuroop
  • 993
  • 3
  • 13
  • 25

1 Answers1

2

You can use Button.wrap() to make a Button out of an Element, e.g.:

Button b = Button.wrap(Document.getElementById("foo"));
b.addClickHandler(new ClickHandler() {
  @Override
  public void onClick(ClickEvent e) {
    hideColumns();
  }
}):
Jason Hall
  • 20,632
  • 4
  • 50
  • 57