Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13914 > unrolled thread
| Started by | "Richard Maher" <maher_rj@hotspamnotmail.com> |
|---|---|
| First post | 2012-04-26 20:42 +0800 |
| Last post | 2012-04-29 18:01 +0800 |
| Articles | 3 — 1 participant |
Back to article view | Back to comp.lang.java.programmer
Java7 Applet Status and Event Handlers "Richard Maher" <maher_rj@hotspamnotmail.com> - 2012-04-26 20:42 +0800
Re: Java7 Applet Status and Event Handlers "Richard Maher" <maher_rj@hotspamnotmail.com> - 2012-04-28 12:28 +0800
Re: Java7 Applet Status and Event Handlers "Richard Maher" <maher_rj@hotspamnotmail.com> - 2012-04-29 18:01 +0800
| From | "Richard Maher" <maher_rj@hotspamnotmail.com> |
|---|---|
| Date | 2012-04-26 20:42 +0800 |
| Subject | Java7 Applet Status and Event Handlers |
| Message-ID | <jnbfsm$10q$1@speranza.aioe.org> |
Hi,
I found the following pages and find them very interesting and useful: -
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/applet/appletStatus.html
http://docs.oracle.com/javase/tutorial/deployment/applet/appletStatus.html
a good example of use: -
http://docs.oracle.com/javase/tutorial/deployment/applet/examples/dist/applet_StatusAndCallback/AppletPageUpdatedDuringLoading.html
The only thing is, I'd really much rather stick to my old and very simple
strategy of "app=document.getElementById(appletId); app.someMethod();" and
block synchronously until the applet is loaded. The problem is that although
that strategy works like a charm with FireFox, Opera, and Safari, it falls
over on slow machines on the JVM initialization when using Chrome or IE :-(
So I'm thinking new Applet event handling in Java 7 would lead one to
believe this is the way to go but, alternatively, if someone can show me a
simple way to reintroduce the blocking behaviour with IE and Chrome I'd much
appreciate it! Some want/require a "lazy load" but I do not!
Cheers Richard Maher
PS. Below is the existing code that I guess I'm going to have to introduce
the JAVA_STATUS_EVENTS parameter to: -
/**
* Copyright (c) Richard Maher. All rights reserved.
*
*/
function Tier3Client(application,
codeBase,
port,
maxBuf,
hostCharSet,
sslReqd)
{
this.facPrefix = "T3$";
this.application = application;
this.codeBase = codeBase;
this.port = port;
this.maxBuf = maxBuf;
this.hostCharSet = hostCharSet;
this.sslReqd = sslReqd;
this.msgPend = new Array();
var appletId = "Tier3__" + application + "_Applet";
try {
var idTaken = document.getElementById(appletId);
}
catch (err) {};
if (idTaken != null) {
throw new Error("Tier3 Client already registered for " +
this.application);
return;
}
var archiveName = "tier3Client.jar";
var className = "tier3Client/Tier3Application";
var appletParams = [{"name":"archive", "value":archiveName},
{"name":"codebase", "value":codeBase },
{"name":"code", "value":className },
{"name":"mayscript", "value":"true" },
{"name":"scriptable", "value":"true" },
{"name":"APPLICATION", "value":application},
{"name":"PORT", "value":port },
{"name":"MAXBUF", "value":maxBuf },
{"name":"HOSTCHARSET", "value":hostCharSet},
{"name":"SSLREQD", "value":sslReqd }];
var startParam = 0;
var objectTag = "<object classid=";
if (/Internet Explorer/.test(navigator.appName)) {
objectTag = objectTag +
'"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
} else {
objectTag = objectTag +
'"java:' + className + '.class" type="application/x-java-applet
" ' +
'archive="' + codeBase + archiveName + '"';
startParam = 1;
}
objectTag = objectTag + ' width= "0" height= "0" id="' + appletId +
'">';
for (i=startParam; i<appletParams.length; i++){
objectTag = objectTag + '<param name ="' + appletParams[i].name +
'" ' +
'value ="' + appletParams[i].value +
'">';
}
objectTag = objectTag + "</object>";
var appletDiv = document.createElement("div");
appletDiv.innerHTML = objectTag;
try {
document.body.appendChild(appletDiv);
this.chan = document.getElementById(appletId);
}
catch(err) {
alert("Tier3 unable to load applet for " + this.application +
": -\n" + err.description);
this.chan = null;
};
if (this.chan == null) {
throw new Error("Tier3 was unable to initialize the applet for " +
this.application);
return;
} else {
if (!this.chan.isAuthorized()) {
throw new Error("Tier3 User authentication unsuccessful for " +
this.application);
return;
}
}
Tier3Client.applications[this.application] = this;
return this;
}
Tier3Client.MAJVERS = 1;
Tier3Client.MINVERS = 0;
Tier3Client.launder =
function(jsobject) {
return jsobject;
};
Tier3Client.prototype = {
send:
function(msgBody, callback)
{
if (arguments.length < 2) {
throw new Error("Insufficient arguments for send(msgBody,
callback)");
}
var chan = this.chan;
var callbackArgs = new Array();
var responseCnt = 0;
var i = 0;
var msgCandidate =
{
msgSlotId : -1,
msgSeqNum : -1,
chan : chan,
callback : callback,
callbackArgs : callbackArgs,
dispatcher :
function(responseMsg,
msgSlotId,
msgSeqNum)
{
this.responseCnt++;
this.msgSlotId = msgSlotId;
this.msgSeqNum = msgSeqNum;
callbackArgs[0] = responseMsg;
try {
callback.apply(this, callbackArgs);
}
catch (err) {
throw new Error("Error calling callback
routine: -\n" + err.description);
}
},
getMsgSeqNum :
function() {
return this.msgSeqNum;
},
getResponseCnt:
function() {
return this.responseCnt;
},
complete :
function() {
return chan.complete(this.msgId);
}
};
if (typeof callback != "function") {
throw new Error("The 'callback' parameter is not a
function");
}
for (i=2; i<arguments.length; i++) {
callbackArgs[i - 1] = arguments[i];
}
return chan.send(msgCandidate, msgBody);
}
};
Tier3Client.applications = {};
[toc] | [next] | [standalone]
| From | "Richard Maher" <maher_rj@hotspamnotmail.com> |
|---|---|
| Date | 2012-04-28 12:28 +0800 |
| Message-ID | <jnfrl8$o1d$1@speranza.aioe.org> |
| In reply to | #13914 |
"Richard Maher" <maher_rj@hotspamnotmail.com> wrote in message
news:jnbfsm$10q$1@speranza.aioe.org...
> Hi,
>
> I found the following pages and find them very interesting and useful: -
> http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/applet/appletStatus.html
> http://docs.oracle.com/javase/tutorial/deployment/applet/appletStatus.html
> a good example of use: -
> http://docs.oracle.com/javase/tutorial/deployment/applet/examples/dist/applet_StatusAndCallback/AppletPageUpdatedDuringLoading.html
>
Ok, the onLoad, onError, and Status attributes all seem to do what it says
on the tin for Applets with Java7 and FireFox, Opera, and even IE.
Unfortunately on Chrome, document.getElementById("myApplet") still returns
before the Applet Object has formed enough so Status is "undefined".
Is there anyway to tell Chrome to wait? Does it have it's own onLoad, or
onReadyStateChange handlers for Applets?
Cheers Richard Maher
[toc] | [prev] | [next] | [standalone]
| From | "Richard Maher" <maher_rj@hotspamnotmail.com> |
|---|---|
| Date | 2012-04-29 18:01 +0800 |
| Message-ID | <jnj3ij$idv$1@speranza.aioe.org> |
| In reply to | #13958 |
"Richard Maher" <maher_rj@hotspamnotmail.com> wrote in message
news:jnfrl8$o1d$1@speranza.aioe.org...
> Ok, the onLoad, onError, and Status attributes all seem to do what it says
> on the tin for Applets with Java7 and FireFox, Opera, and even IE.
> Unfortunately on Chrome, document.getElementById("myApplet") still returns
> before the Applet Object has formed enough so Status is "undefined".
>
> Is there anyway to tell Chrome to wait? Does it have it's own onLoad, or
> onReadyStateChange handlers for Applets?
In case anyone's interested in the outcome, for the sake of Chrome I had to
put a setTimeout poll (hate it!) on the
document.getElementById("appletId").status - for example: -
var waitForAppletDOM = function() {
if (window.console) console.log("in waitForAppletDOM");
var appletStatus = ((chanG.status||undefined) == undefined) ? 0
: chanG.status;
switch (appletStatus) {
case 0:
if (window.console) console.log("case 0");
setTimeout(waitForAppletDOM,250);
break;
case 1:
if (window.console) console.log("case 1");
chanG.onLoad = appletLoad;
chanG.onError = appletError;
break;
case 2:
if (window.console) console.log("case 2");
alert("Applet is already loaded");
break;
case 3:
if (window.console) console.log("case 3");
throw new Error("Error activating Applet");
break;
default:
throw new Error("Invalid Applet status");
}
Needles to say, Windows/Safari is a dead bloody loss :-( Also note that, for
FireFox and Opera, if you do an "alert('some-debug-stuff')" from you
"onError" handler the our browser freezes.
>
> Cheers Richard Maher
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web