Nish
Nish

Reputation: 137

Call injected java script's function from GWT

I have GWT application, html file and javascript file. In GWT application, I am loading html files in GWT HTML Panel and then injecting javasript on that. I have defined couple of functionality like "submit", "cancel" etc.. in javasript file. I have corresponding button in GWT client page too. Now, when i click on submit button on gwt client page, it should invoke "submit" function of javascript file.

code from javascript file:

$('#submitButton').click( function () {
      alert('submit clicked');
      dosomething();
    }
  });

I have tried using JSNI as below from GWT client page.

public native JavaScriptObject submitForm()/*-{
        return $doc.submitButton(); // tried with $wnd.submitButton() as well.
    }-*/;

but it does not work and throws following error

com.google.gwt.event.shared.UmbrellaException: Exception caught: (TypeError)  $doc.submitButton is not a function

Upvotes: 1

Views: 542

Answers (1)

Igor Klimer
Igor Klimer

Reputation: 15321

The error seems pretty clear - you are invoking submitButton which is not a function (it's probably undefined, unless you did something else besides the code shown). You should probably do something like: $wnd.jQuery('#submitButton').click().

Upvotes: 1

Related Questions