Tuesday, January 22, 2019

Error When Calling java method via JSNI - Cannot read property 'apply' of undefined

GWT 2.8.0


I am pulling my hair out with this error.  Hoping someone can help.  I am calling a Java method (in a GWT class) from an external javascript file.  I've done this without issue with several other java calls.  However, when I make the call from javascript to GWT and try to pass any parameters from javascript to the GWT method via JSNI, I get a cryptic error that I am unable to trace.


Javascript function  (used this same pattern on multiple occasions without issue)
function openJobDetailsDialog(){
this.displayJobDefinitionDialog("1", "2", "3");
}


GWT methods:

public native void displayJobDefinitionDialog(String jobId, String jobType, String serviceId) /*-{
$wnd.displayJobDefinitionDialog = $entry(@com.function.operation.Class::handleJobDefinition(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(jobId, jobType, serviceId));
}-*/;
public static void handleJobDefinition(String jobId, String jobType, String serviceId) {
if(jobId != null) {
MessageDialog.MessageOk("", "handleJobDefinition for jobId: " + jobId + " jobType: " + jobType + " serviceId: " + serviceId, null);   //utility method to help with debugging


                        //other logic here......
}
}


If I remove the parameters (Ljava/lang/String;) from the the handleJobDefinition() method, it gets called fine and the MessageDialog utility class displays the message I expect to see.  Adding the parameters to the calls does NOT result in a compile error.  However, after adding the parameters to the calls, I see the following at runtime:

com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'apply' of undefined
=>Unknown.apply_0() at com.function.operation.tes.TES-0.js[-1]
=>Unknown.entry0_0() at com.tidalsoft.webclient.tes.TES-0.js[-1]
=>Unknown.anonymous() at com.tidalsoft.webclient.tes.TES-0.js[-1]
=>Unknown.openJobDetailsDialog() at http://localhost:8081/client/businessViews.js[-1]

I've tried removing the "$wnd.displayJobDefinitionDialog =" from the displayJobDefinitionDialog call and while that does compile, I get an error indicating that the function cannot be found (which makes perfect sense).  

The GWT documentation is a little sparse in this area.

Any help is greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment