0

I want to call an external javascript function in my gwt application

when i use this code it works fine : i have imported javaScript and i can see it in firebug in client side

public static native void showOfflineMap(String pRegionId, String pMapServerHost, String pMapServerPath, String pMapTileLayers, String pFoiLayers,
            double pMapCenterLon, double pMapCenterLat, int pInitZoom, String pNavPanel, boolean pCustJsFunction, int pMapWidth, int pMapHeight,
            String pAdditional) /*-{
                                alert("ff");
                                                $wnd.createPluginMap(
                                                pRegionId,
                                                pMapServerHost,
                                                pMapServerPath,
                                                pMapTileLayers,
                                                pFoiLayers,
                                                pMapCenterLon,
                                                pMapCenterLat,
                                                pInitZoom,
                                                pNavPanel,
                                                pCustJsFunction,
                                                pMapWidth,
                                                pMapHeight,
                                                pAdditional
                                                )


                                                }-*/;

but when i remvoe

alert("ff");

it throws this exception :

Sun Jul 06 16:36:49 GMT+03:30 2014 com.google.gwt.logging.client.LogConfiguration
SEVERE: (TypeError) @ir.dena.avl.client.offlinemap.MapUtil::showOfflineMap(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DDILjava/lang/String;ZIILjava/lang/String;)([string: 'offline_map', string: 'http://192.168.10.196:7001', string: '/mapviewer', string: 'mp.LINE_TILE', string: 'NONE', double: 56.0046, double: 32.629365, int: 3, string: 'WEST', bool: false, int: 1000, int: 800, string: 'OVER:MARQUEE:DISTANCE:REDLINE:FOISELECT']): $wnd.createPluginMap is not a functioncom.google.gwt.core.client.JavaScriptException: (TypeError) @ir.dena.avl.client.offlinemap.MapUtil::showOfflineMap(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DDILjava/lang/String;ZIILjava/lang/String;)([string: 'offline_map', string: 'http://192.168.10.196:7001', string: '/mapviewer', string: 'mp.LINE_TILE', string: 'NONE', double: 56.0046, double: 32.629365, int: 3, string: 'WEST', bool: false, int: 1000, int: 800, string: 'OVER:MARQUEE:DISTANCE:REDLINE:FOISELECT']): $wnd.createPluginMap is not a function
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
    at ir.dena.avl.client.offlinemap.MapUtil$.showOfflineMap(MapUtil.java)
    at ir.dena.avl.client.offlinemap.OfflineMapView.createMainPanel(OfflineMapView.java:31)
    at ir.jalal.core.client.view.BaseView.<init>(BaseView.java:71)
    at ir.dena.avl.client.offlinemap.OfflineMapView.<init>(OfflineMapView.java:20)
    at ir.dena.avl.client.ViewFactory$32.onSuccess(ViewFactory.java:354)
    at com.google.gwt.core.client.GWT$1.execute(GWT.java:286)
    at com.google.gwt.core.client.impl.SchedulerImpl$Task$.executeScheduled$(SchedulerImpl.java:50)
    at com.google.gwt.core.client.impl.SchedulerImpl.runScheduledTasks(SchedulerImpl.java:180)
    at com.google.gwt.core.client.impl.SchedulerImpl.flushPostEventPumpCommands(SchedulerImpl.java:345)
    at com.google.gwt.core.client.impl.SchedulerImpl$Flusher.execute(SchedulerImpl.java:78)
    at com.google.gwt.core.client.impl.SchedulerImpl.execute(SchedulerImpl.java:138)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:356)
    at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)

please help me,

thanks in advance

2 Answers 2

1

Make sure that you link your script with createPluginMap function before .nocache.js and doesn't link it asynchronously (I mean it should be without <script defer or <script async)

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

1 Comment

this silly mistake of having the scripts before .nocache.js held me for 4 days. Thanks
0

I assume it's a race condition and the function createPluginMap doesn't exist when you expect it be.

Try replaceing

alert("ff");

with

alert(''+!!$wnd.createPluginMap);

If you get 'false' in the alert, this is the reason. If true, i will try to think of a different answer ;)

2 Comments

i do this ,but it still throws that exception
It might also be because of dev mode. Try validating this with using the final js and not dev mode. Or try using SuperDevMode: gwtproject.org/articles/superdevmode.html

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.