PDA

View Full Version : problem in calling applet function in mozilla


vikaspawar
04-17-2008, 06:59 AM
Friends i'm callling a function of applet from javascript

first used the jsp plugin to call applet
to display a tree then call a function of applet which is
public void remove() {
DefaultMutableTreeNode selectedNode = getSelectedNode();
if (selectedNode != null)
model.removeNodeFromParent(selectedNode);
}
this is the applet function and
in jsp i called this function from javascript as

document.frmaddcategory_dyna.tree.remove();
(form name). (name of jspplugin) .(method)
In IE it performs well but in mozila it doesnt work as
error is document.frmaddcategory_dyna.tree.remove is not a function
also tried this ocument.tree.remove(); but still there is error

is it correct method to call the method of applet from javascript
or any other plz reply me

thanks for ur reply

vikaspawar
04-17-2008, 08:22 AM
hi find d solution for this

first just
var applet=document.getElementById("tree");
applet.remove();

support for mozilla as well

my new question is how to save tree object and send it to servlet

mjlorbet
04-18-2008, 05:30 AM
really, i have no idea what any of this means without the context of the page you're trying to operate on, so please post the page as well so we can figure out what exactly tree is and what manner of data it contains and how to get/serialize it for transmission back to the servlet (can be done with ajax, guessing that's why you posted it here). and for future reference, please always put your code inside tags, it's much easier to read.

vikaspawar
04-18-2008, 01:18 PM
thanks for ur reply
{code}
public void remove() {
DefaultMutableTreeNode selectedNode = getSelectedNode();
if (selectedNode != null)
model.removeNodeFromParent(selectedNode);
}
{code}
this is one mehod written in applet

in jsp
{code}
<jsp:plugin type="applet" code="ModelJTree1.class" name="tree" codebase="." height="300" width="400" jreversion="1.6" >
<jsp:params>
<jsp:param
name="session1"
value="<%=session1%>"/>



</jsp:params>

<jsp:fallback>
<B>Unable to start plugin!</B>
</jsp:fallback>

{code}
applet is called in jsp page
and now as i want to call the method of applet using js
so i used a function which is

{code}
//function to call applet method remove
var function addtoapplet()
{
var applet=document.getElementById("tree");
applet.remove();
}
{code}

by using this i can remove the added node of the applet
and it works in IE and Mozilla also

mjlorbet
04-18-2008, 02:20 PM
remove is the only method in your applet? what information are you trying to save? code tags are (the # sign in the editor)

shyam
04-23-2008, 04:51 PM
t
<jsp:plugin type="applet" code="ModelJTree1.class" name="tree" codebase="." height="300" width="400" jreversion="1.6" >
...

//function to call applet method remove
var function addtoapplet()
{
var applet=document.getElementById("tree");
applet.remove();
}

you only specify the name attribute of the applet tag that is generated not its id...IE helpfully gives an element with the name/id when you call document.getElementById and mozilla strictly returns only elements that have its id set to tree...

you could instead use

var applet = document.getElementsByName('tree')[0]; the document.getElementsByName is a recent addition and might not be widely supported