Hi
I’m working on the project where I need your component again
While I was testing application I saw that in Google Chrome user must click two times on button to call execute method of the applet. I thought the problem is with my implementation, so I visited http://sami.virtuallypreinstalled.com/screenshot to see how does it work. Same thing there. In debug console we get:
Applet command: v-appletPID11,‘screenshot’,‘null’
JavaScriptException: (TypeError): Object [object HTMLAppletElement]
has no method ‘execute’
Processing time was 62ms for 778 characters of JSON
After bit of analyzing I figured out that error pops out because javascript is calling applet before it has been loaded (?). Because of that I added few lines of code to be sure that applet is loaded before calling execute method. Here is the code:
VAppletIntegration:
added methods
private native static boolean isAppletLoaded()/*-{
return $wnd.vaadin.isAppletLoaded();
}-*/;
private native static void exportJSFunctionsForAppletStatistics()/*-{
var appletLoaded = false;
$wnd.vaadin.setAppletLoaded = function(loaded){
appletLoaded = loaded;
}
$wnd.vaadin.isAppletLoaded = function(){
return appletLoaded;
}
}-*/;
I also modified updateFromUIDL(UIDL uidl, ApplicationConnection client) method.
...
if (!appletInitialized) {
exportJSFunctionsForAppletStatistics(); //added this line
// Applet class
if (!uidl.hasAttribute(ATTR_APPLET_CLASS)) {
VConsole.log("Missing attribute " + ATTR_APPLET_CLASS);
return;
}
appletClass=....
At the end of this method I added lines:
...
if (cmd != null) {
timer=new Timer() {
@Override
public void run() {
if (isAppletLoaded()) {
VConsole.log("Command: "+cmd);
execute(cmd, cmdParams);
cancel();
}
}
};
VConsole.log("Waiting for applet to load!!!");
timer.scheduleRepeating(100);
}
AbstractVaadinApplet:
public void setAppletLoaded(){
String cmd = "vaadin.setAppletLoaded(true)";
jsCall(cmd);
}
Now in my applet as last line of the init() method i put setAppletLoaded()
Basically the applet informs client side that he is ready. This works fine, but if there is a better solution I would like to use it.
Regards
Veselin