PDA

View Full Version : Calling ExtJs method in Applet using JsObject



saiaravind
14 Aug 2013, 6:51 AM
Hi,

I am embedding applet in an ExtJs window. I have a functionality where in i need to invoke a function written in the window from applet, but this doesnt seem to work with the below code.


Ext.onReady(function () { Ext.create('Ext.window.Window', {
title : "iframe",
width : 300,
height: 300,
layout : 'fit',

items : [{
xtype : "component",
autoEl : {
tag: 'applet',
archive: 'resources/helloworld.jar',
code: 'HelloWorld',
codebase: "."
}
}],
sayHello : function(content) {
alert(content);
}
}).show();
});

I tried to use the same applet with a simple html code which worked perfectly.

HTML

<html><title>The Hello, World Applet</title>
<head>
<script>
function sayHello(content) {
alert(content);
}
</script>
</head>
<applet archive="helloworld.jar" code="HelloWorld" width="320" height="120"/>
</html>

Applet

public void paint(Graphics g) { try {
JSObject window = JSObject.getWindow(this);
Object[] args = new String[] { "Hello World from Javascript" };
window.call("sayHello", args);
}
catch(Exception e) {
g.drawString(e.getMessage(), 10, 10);
}
g.drawString("Hello world! :: "+new Date(), 10, 25);
}

Please let me know what changes are to be done to get the function invoked in ExtJs Window.

Thanks,
Arvind

Gary Schlosberg
19 Aug 2013, 1:23 PM
I'm know little Java, but seems like a scope issue. Thinking that the JSObject.getWindow() call in your applet needs to be modified to get the Ext.window.Window scope instead of the global window?

Scorpie
19 Aug 2013, 1:29 PM
Why not communicate with a controller instead of a view?

Appname.GetApplication().getController('Controllername').doSomething() will probably work, provided you have setup your application correctly.