getMember() return null

I have some difficulties in applet communicating to javascript.I use IE5 and sun plug-in1.3.

The html file is:

<objectname="sign" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" mayscript

width = 80 height = 16 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">

<param name = CODE value = "TSignApplet" >

<PARAM NAME = CODEBASE VALUE = "." >

<param name = ARCHIVE value = "TSignApplet.jar" >

<PARAM NAME="MAYSCRIPT" VALUE="true" >

<param name="scriptable" value="true" >

<param name="type" value="application/x-java-applet;version=1.3">

<comment></comment> <embed type="application/x-java-applet;version=1.3" java_code = "TSignApplet" java_archive = "TSignApplet.jar" width = 500 height = 500pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html">

<noembed> </noembed>

</embed>

</object>

<form name="theForm" id="theForm">

<input type="button" name="ss" value="sign" onClick="document.sign.hello(document.theForm)">

<input type="text" name="myText" value="demo" >

</form>

The applet method is:

public void hello(JSObject form)

{

try{

if (form==null)

{

System.out.println("the form is null");

}

else

{

System.out.println("form object transfered");

}

System.out.println("object is: "+form.toString());

String name=(String)form.getMember("name");

System.out.println("the form name is:"+name);

JSObject text=(JSObject)form.getMember("myText");

if (text==null)

{

System.out.println("sigh...,the text object is null");

}

}

catch(JSException jse)

{

System.out.println("exception");

}

}

The output is:

form object transfered

object is: sun.plugin.javascript.ocx.JSObject@1671b2

the form name is:null

sigh...,the text object is null

Why does happen?

Thanks in advance.

[2539 byte] By [DeltaY] at [2007-9-26 4:33:59]
# 1

A roundabout way around this problem (one that works however) is :

write a JavaScript function in the web page containing the applet, that does what you precisely need, i.e. calls a function in your applet that sets the value of the text string in your applet to the value of the myText field in the web page. Say we call the JavaScript function setTextStringInApplet()

Make a corresponding function in your applet to set the value of the text String (call it setMyTextString(String s)).

sayTextStringInApplet(), the JavaScript function, therefore calls

myApplet.setMyTextString(form.myText.value)

When the applet needs the value of the myText variable, it gets a ref to the JSObject of the page containing it and then invokes the JavaScript function setTextStringInApplet() via the code:

JSObject htmlDoc = (JSObject) getWindow(this);

htmlDoc.setTextStringInApplet()

Like I said its roundabout, but it works.

cheers

-Ragu

Uncle Ed's Rule of Thumb:

Never use your thumb for a rule.

You'll either hit it with a hammer or get a splinter in it.

ragude at 2007-6-29 17:50:00 > top of Java-index,Desktop,Deploying...