calling second applet once first applet is loaded in JSP/JSF/HTML - java

I am working on a JSP/ JSF page where two applets are embeded using tag.
Problem is the first applet is having some information that will be updated on the page and the second applet must use that info to load properly.
I cannot find a way where i can control calling of the applets. (These applets are third party applets other wise i could have combined both applets). i want to know how i can know the first applet is loaded and then call/enable or show 2nd applet.
below are the tags i used for applets on my page.
<object
name="CSHelper" id="CSHelperId"
classid="clsid:9C840-044E-11D1-B3E9-5F499D93"
width="100%"
HEIGHT="0"
ALIGN="middle"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0_11-windows-i586.cab#Version=1,5,0,11">
<param name="code" value="ClientUtil"/>
<param name="ARCHIVE" value="HelperApplet.jar"/>
</object>
<object style="display:none"
name="ivrTelephonyBarName" id="ivrTelephonyBarId"
classid="clsid:89C840-044E-11D1-B3E9-0599D93"
width="100%"
HEIGHT="75"
ALIGN="middle"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0_11-windows-i586.cab#Version=1,5,0,11">
<param name="code" value="<%=cTIConnectionParams.getAppletJarClass()%>"/>
<param name="ARCHIVE" value="<%=cTIConnectionParams.getAppletJar()%>"/>
<param id="AGENT_ID" name="AGENT_ID" value="<%=cTIConnectionParams.getAgentID()%>"/>
<%--<param id="sAgentID" name="sAgentID" value="0202"/>--%>
<param id="AGENT_PASS" name="AGENT_PASS" value="<%=cTIConnectionParams.getAgentPassword()%>"/>
<param id="INSTRUMENT" name="INSTRUMENT" value="<%=cTIConnectionParams.getInstrument()%>"/>
<param id="params" name="params" value="<%=cTIConnectionParams.getParams()%>"/>
<param id="iconsPath" name="iconsPath" value="<%=contextCtiUrl%>images/appletIcons/"/>
<param id="configPath" name="configPath" value="<%=contextCtiUrl%>"/>
</object>
I want to laod "CSHelperId" first and then the last when which is not diaplyed purposely.
Any technique will work for me.

you can do it mixing javascript code in your 1st applet
public void init() {
JSObject document = JSObject.getWindow(this);
String evalString = "document.getElementById('secondAppletPanel').innerHTML = ";
document.eval(evalString + secondAppletHtmlString);
}
now you can build a string with parameters calculated by your first applet modifiyng the string content, also
you need to place and empty div with id secondAppletPanel where you want the second applet to appear and add the mayscript attribute to your first applet (more info JSObject
)

Related

applet tag vs Object tag

As per W3Schools HTML applet tag is not supported in HTML5. Need to use <Object> tag instead of <applet> tag.
For more details follow this link: http://www.w3schools.com/tags/tag_applet.asp
http://dev.w3.org/html5/spec/obsolete.html#the-applet-element
Point 11.2 Non-conforming features
So, I go ahead and the change the code.
Below code that is working with <APPLET> tag:
<Applet
style = "position:absolute;border:0px;left:184;top:95;height:180;width:364;"
code = "jtreeviewapplet.JTreeViewAppletMain.class"
name = "TreeView"
id = "TreeView"
hspace = "0"
vspace = "0"
align = "top"
archive = "/Project/HTML/ABC/XYZ.jar,/Project/HTML/ABC/ABC.jar"
MAYSCRIPT>
<PARAM NAME="onSelected" VALUE="onSelect_Handler">
<PARAM NAME="onFinishNormalize" VALUE="onFinishNormalize_Handler">
</Applet>
Here is the snippet; I changed <APPLET> tag to <OBJECT> tag so as to support HTML5 in future:
<OBJECT type=" application/x-java-applet"
style = "position:absolute;border:0px;left:184;top:95;height:180;width:364;"
name = "TreeView"
id = "TreeView"
hspace = "0"
vspace = "0"
align = "top"
>
<PARAM name="code" value=”jtreeviewapplet.JTreeViewAppletMain.class”>
<PARAM name="codebase" value="/Project/HTML/ABC/">
<PARAM name="archive" value=" XYZ.jar">
<PARAM name="archive" value=" ABC.jar">
<PARAM name="scriptable" value="true">
<PARAM NAME="onSelected" VALUE="onSelect_Handler">
<PARAM NAME="onFinishNormalize" VALUE="onFinishNormalize_Handler">
</OBJECT>
After changing the <applet> tag to <object> tag , my applet itself is not loading and it gives class not found exception for jtreeviewapplet.JTreeViewAppletMain.class.
(Note: For both working and not working condition, I am using latest JDK 1.7 update 9 for compiling the code and in my system I am having latest JRE1.7 update 9 to run the applet code. I am using InternetExplorer 8 and InternetExplorer 9 browser)
Just replacing applet by object isn't enough. Read http://www.ailis.de/~k/archives/63-How-to-use-Java-applets-in-modern-browsers.html for an example.

Javascript does not find Applet in IE9

i have got a Problem with Javascript and it´s Communication to an applet.
In every Browser Javascript does find the applet and i can call it´s methods, but in IE9 it does not find the object/applet. heres the code
<div class="speichern" align="center">
<object type="application/x-java-applet" width="10" height="10" id="jsap" name="jsap">
<param name="archive" value="ABD_Downloadmanager.jar,ojdbc6.jar"> </param>
<param name="code" value="Speichern_Applet.class"> </param>
<param name="mayscript" value="yes">
<param name="scriptable" value="true">
</object>
</div>
and the Javascript call :
var appletObj = document.getElementsByName('jsap')[0];
var path = appletObj.test();
the test Method does just return a String return "C:/";
when i use the an alert(appletObj );
Firefox does show me object HtmlObjectElement
But the IE does only show object
i have tried this ways to get the applet without any success:
var appletObj = document.getElementsByID('jsap')[0];
var appletObj = document.getElementsByID('jsap');
var appletObj = document.jsap;
var appletObj = document.applets[0];
for me it looks like the IE simply cannot work with the object tag or something like this? someone got a solution for this or an idea why the IE can not find the object/applet?
Thanks for reading so far
I Just found out the Problem which came up in here.
I was using the style='visible:hidden' attribute. But a hidden DOM object, in this case the Object tag/ applet won´t be loaded by the IE. I just had to set the size to (0,0). Genius...

calling id from applet object throws js error in IE

When calling an applet id from JS giving Object doesn't support this property or method error.
Please check the code...
<!--[if !IE]> Firefox and others will use outer object -->
<object
classid = "java:com.mypack.myclass.ABCClass.class"
type = "application/x-java-applet"
height = "200"
width = "480"
id = "myappletId">
<!-- Konqueror browser needs the following param -->
<param name="cache_archive" value="a.jar, b.jar, c.jar" />
<param name="codebase" value="applets/" />
<param name="OnMouseLeftClickJS" value="showModal()">
<!--<![endif]-->
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
<object
classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"
height = "200"
width = "480"
id = "myappletId">
<param name="code" value="com.mypack.myclass.ABCClass" />
<param name="cache_archive" value="a.jar, b.jar, c.jar" />
<param name="OnMouseLeftClickJS" value="showModal()">
<param name="codebase" value="applets/" />
<strong>No Java Support</strong>
</object>
<!--[if !IE]> close outer object -->
</object>
<!--<![endif]-->
Now, in my showModal() js function I have,
var myId = document.getElementById("myappletId"); //At this point I am getting the object data.
I perform some operations in my modal window which is a jquery modal window and I have a button in it. When I click on that I am calling a function say xyz().
function xyz() {
var myId = document.getElementById("myappletId");
//At this point myId is getting empty.
}
This is happening in only IE Browser. I tested in IE8.
Works good in Firefox and chrome.
I am not navigating my page and on view source I can see my object tag.
Please help me out.
Thanks in advance...
In your comments you have
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
How about using document.getElementById('myappletId').getElementById('innerApplet') ?
It would be great idea to use unique id for inner applet, maybe then your solution would work.
Thanks for your effort guys, the mistake is in my code. When I open a modal window making the object tag visibility hidden in the back. Even I am make it visible after closing the modal window, This IE is not identifying it. Weird but true...

When Object tag is display:none, method fails, but when visibility:hidden works

I have a span tag as parent to an object tag that loads a Java class. The span tag has style display:none. When a reference to the object tag is retrieved in Javascript and a method of this object tag is called, it fails.
But, if the span tag does not have display:none set OR visibility:hidden, then it works.
Why is this?
<span style='display:none'>
<object type="application/x-java-applet" width="100" height="100" name="my_class" id="my_class">
<param name="codebase" value="http://www.whatever.com/class">
<param name="code" value="myclass.class">
<param name="mayscript" value="yes">
<param name="scriptable" value="true">
</object>
</span>
This is basic styles (CSS), a hidden object is still included in the page, while an element with display:none is not even included.
Solution:
Make the applet around 10x10 pixels in size
Put it in some innocuous part of the web page (e.g. at the end)
Use visibility:hidden to hide it from view. Note that is visibility, not display!
Larry.
The reason is that when using 'display:none' browser renders the page as though the element was not there at all. Although you can get the referrence to the 'object' element in DOM, but object itself hasn't been created yet. On the other hand 'visibility:hidden' only hides the element, but it still takes up space and layout.
The best solution to not break page layout is to make your element absolutely positioned and take it in some place outside the user sight (e.g. left:-1000px)

How to add new parameters to a java applet to call another method from javascript?

I am using a java applet to call Web Services. This java applet is embedded in a html web page like this :
<object classid="java:TEST3.class"
codebase="lib/"
type="application/x-java-applet"
width="5000" height="50"
archive="sTest11.jar" name="TEST3" id="TEST3">
<param name="TEST3" value="TEST3" />
alt : TEST3.class
<!-- Safari needs this -->
<param name="JAVA_CODEBASE" value="lib" />
<param name="BGCOLOR" value="000000" />
<param name="TEXTCOLOR" value="FF0000" />
<param name="TEXT" value="Test" />
<param name="SPEED" value="250" />
<param name="RANDOMCOLOR" value="1" />
<param name="mayscript" value="yes"/>
<param name="scriptable" value="true" />
</object>
So when the web page is opened, the applet starts. I have a javascript file which calls the init() method to call a first web service. Then I retrieve datas, that I need to call a second web service. That's why I need here to add parameters to my java applet. If I use in javascript :
document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';
and then
javascript:document.getElementById('TEST3').mymethod2();
it does not work. The applet is not reloaded. (but it works if I put manually a parameter before loading the whole page, so the problem is the reloading of the applet in order to take the new parameter).
I tried to call the stop() method, then the destroy() one, then another init() and then the request I want but it does not work.
I manage to do my requests with different applets (with several innerHTML which create each one applet step by step), but it does not work exactly as I want, and I really would prefer use only one.
If you have any idea, thank you very much for your help.
Try invoking your function like this instead:
document.TEST3.mymethod2();
And see if that works.
EDIT
Based off your comments I understand you were trying to pass additional startup parameters to the Applet on your page. Which is of course not really possible (keyword startup :). With your first method you had this:
document.getElementById('TEST3').innerHTML +='<param name="PARAM1" value="'+var1+'"/>';
But your object tag (correctly) doesnt have any innerHTML. And params are not specified in the object tag body anyway so no matter what this will have no useful effect. Your second method had this:
javascript:document.getElementById('TEST3').mymethod2();
Which according to your comments works, but of course there is no data getting passed in so your Applet parameters do not change. What you do want to do is this:
javascript:document.getElementById('TEST3').mymethod2(someparameter);
Of course, your method signature on the Applet should match!

Categories