Can we call JSNI method like this?

panel.getElement().setAttribute("onclick", "hide()");

public static native void hide() /*-{;

It doesn't call the hide() method on click. Probably, it's unable to find the method. Is there any workaround ?

I only want to call GWT hidePage() either from external JS or from attribute's JS code.

This doesn't work because the hide method will be assigned an obfuscated name when it is converted into JavaScript. It would be better to use something like addEventListener to attach the function reference instead.

1 Like

Something like this ?

public static native void hide(Element element) /*-{    
element.addEventListener('onclick', function (e) {;

You'll also need a reference to button, which right now isn't declared anywhere as far as I see.

var button = this;

This would be okay ?

Because the function is static, this will be bound to the window rather than your object.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.