1

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

1 Answer 1

1

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().

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Igor. With your suggestion, now I am not getting error, but it is also not hitting javascript function. I tried by giving random name like $wnd.jQuery('#submitButtonDoesNotExist').click(), i was expecting some error, but no error and nothing happens.
Can you trigger the click from the Javascript console (the one in Firebug, Chrome Developer Tools, etc.)? Just put there jQuery('#submitButton').click() (no need for the $wnd part here). Have you checked you really have an element with id submitButton in the DOM when you try to trigger the call from GWT?
Thanks Igor. Added an element with id submitButton in html file as well and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.