Mobile Development 10.11 | webMethods Mobile SuiteWeb Help | webMethods Mobile Designer Native User Interface Reference | Mobile Designer Native User Interface | JavaScript Bridge | Sending a Message to JavaScript from Java
 
Sending a Message to JavaScript from Java
Messages are sent using the callJavaScript() method on the nUIWebView or nUIWebviewElement. You must specify the name of a JavaScript function to call and an array of java.lang.String objects for the functions's arguments. If no arguments are required, a string array of length 0 (zero) should be used. This is an example for two JavaScript functions, myFirstMethod() and mySecondMethodWithArgs(param1, param2):
//call myFirstMethod() to do something
myWebView.callJavaScript("myFirstMethod", new String[]{});
//call mySecondMethodWithArgs with "one" and "two" as arguments
myWebView.callJavaScript("mySecondMethodWithArgs", new String[]{"one", "two"});
Using callJavaScript() in this manner will cause execution on the Java side to wait for a return value. You can also pass an additional parameter to callJavaScript() that will allow the JavaScript function to return a string value to Java. Pass in a reference to a class that implements the NativeUI interface com.softwareag.mobile.runtime.nui.IJSCallback.