Hello,
I want to use a JavaScript library inside an addon that I am currently working on.
I added the according @JavaScript annotation on my AbstractJavaScriptExtension (it is going to be an extension, not a component):
@JavaScript({"vaadin://addons/js/mylib.js"})
public class MyExtension extends AbstractJavaScriptExtension {
}
The library is located inside
src/main/resources/VAADIN/addons/mylib.js
.
Now inside my connector I want to use the library inside the extend() method that is calling a JSNI method:
[code]
@Connect(MyExtension.class)
public class MyExtensionConnector extends AbstractExtensionConnector {
@Override
protected void extend(ServerConnector target) {
callJsniMethod();
}
private native void callJsniMethod() /*-{
var myVar = new $wnd.MyLib.MyClass();
}-*/;
}
[/code]Now by using the console inside the Chrome Developer Tools I can see that I get an error that “MyLib” is not defined at the moment of execution (I set a breakpoint).
Later on, once the page is fully loaded, I can create an instance inside the console.
Am I doing something wrong or is the library loaded too late or whats going on here?
Thank you already for your help!