Urgent: Calling a method of a java object (getting a boolean parameter) from java script

E

Eyal

Hey,

I would appriciate if anyone can help on this one:

I have a java object/inteface having a method with a boolean
parameter. As I'm trying to call this method from a javascript it
fails on a type mismatch.
It is positively because of the boolean(java primitive)parameter. It
goes fine if I change this parameter to int or String.
This inteface has a lot more methods which works fine, it is just the
one with the boolean parameter who makes problems.

Another thing I have noticed is that if I put the same method in an
applet and call it from the javascript it goes fine.

Please note that I'm using IE with plugin of 1.3.1_08.

my code lokks as following:

-------------------------
Java Code:
-------------------------

package name.space.interfaces;

interface IMyInterface1
{
public IInteface2 newJavaObject2();
public void method3(boolean param1);
}

interface IMyInterface2
{
public void method1(String param);
public void method2(int param);
public void method3(boolean param);
}

--------------------------------------------
package name.space.myObject2;

public class MyJavaObject2 implements IMyInterface2
{
public void method1(String param)
{
some code....
}

public void method2(int param);
{
some code....
}

public void method3(boolean param);
{
some code....
}
}
----------------------------------------------------
package name.space.TestApplet;

public class MyApplet extends Applet implements IMyInterface1,
{

public void method3(boolean param)
{
some code....
}

public IMyInteface2 newJavaObject2()
{
IMyInteface2 result = new MyJavaObject2();
return result;
}
}


-------------------------
javascript Code:
-------------------------

<script language=JavaScript>
function Execute()
{
var myApplet = document.myApplet;
myApplet.method3(false);//this one is fine (getting boolean)

var myJavaObj2 = myApplet.newJavaObject2();
myJavaObj2.method1("Test"); //this one is fine (getting String)
myJavaObj2.method2(1); //this one is fine (getting int)
myJavaObj2.method3(false); //this one fails (getting boolean)
myJavaObj2.method3("false"); //this one fails (getting boolean)
myJavaObj2.method3(0); //this one fails (getting boolean)
myJavaObj2.method3(""); //this one fails (getting boolean)
}
</script>

-------------------------
Html Code (plug in tag):
-------------------------

<OBJECT ID="SmartFileCatalog"
classid="clsid:CAFEEFAC-0013-0001-0008-ABCDEFFEDCBA" WIDTH = 100
HEIGHT = 100 NAME = "MyApplet"
codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_08-windows-i586.cab#Version=1,3,1,8">

<PARAM NAME = CODE VALUE = "name.space.TestApplet.class" >
<PARAM NAME = CODEBASE VALUE = ".">
<PARAM NAME = NAME VALUE = "MyApplet" >
<PARAM NAME = ARCHIVE VALUE = "MyTestApplet.jar" >
<PARAM NAME = "type"
VALUE="application/x-java-applet;jpi-version=1.3.1_08">
<PARAM NAME = "scriptable" VALUE="true">

</OBJECT>
 
L

Laurent Bugnion, GalaSoft

Hi,
Hey,

I would appriciate if anyone can help on this one:

I have a java object/inteface having a method with a boolean
parameter. As I'm trying to call this method from a javascript it
fails on a type mismatch.
It is positively because of the boolean(java primitive)parameter. It
goes fine if I change this parameter to int or String.
This inteface has a lot more methods which works fine, it is just the
one with the boolean parameter who makes problems.

Another thing I have noticed is that if I put the same method in an
applet and call it from the javascript it goes fine.

Please note that I'm using IE with plugin of 1.3.1_08.

my code lokks as following:

-------------------------
Java Code:
-------------------------

package name.space.interfaces;

interface IMyInterface1
{
public IInteface2 newJavaObject2();
public void method3(boolean param1);
}

interface IMyInterface2
{
public void method1(String param);
public void method2(int param);
public void method3(boolean param);
}

--------------------------------------------
package name.space.myObject2;

public class MyJavaObject2 implements IMyInterface2
{
public void method1(String param)
{
some code....
}

public void method2(int param);
{
some code....
}

public void method3(boolean param);
{
some code....
}
}
----------------------------------------------------
package name.space.TestApplet;

public class MyApplet extends Applet implements IMyInterface1,
{

public void method3(boolean param)
{
some code....
}

public IMyInteface2 newJavaObject2()
{
IMyInteface2 result = new MyJavaObject2();
return result;
}
}


-------------------------
javascript Code:
-------------------------

<script language=JavaScript>
function Execute()
{
var myApplet = document.myApplet;
myApplet.method3(false);//this one is fine (getting boolean)

var myJavaObj2 = myApplet.newJavaObject2();
myJavaObj2.method1("Test"); //this one is fine (getting String)
myJavaObj2.method2(1); //this one is fine (getting int)
myJavaObj2.method3(false); //this one fails (getting boolean)
myJavaObj2.method3("false"); //this one fails (getting boolean)
myJavaObj2.method3(0); //this one fails (getting boolean)
myJavaObj2.method3(""); //this one fails (getting boolean)
}
</script>

-------------------------
Html Code (plug in tag):
-------------------------

<OBJECT ID="SmartFileCatalog"
classid="clsid:CAFEEFAC-0013-0001-0008-ABCDEFFEDCBA" WIDTH = 100
HEIGHT = 100 NAME = "MyApplet"
codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_08-windows-i586.cab#Version=1,3,1,8">

<PARAM NAME = CODE VALUE = "name.space.TestApplet.class" >
<PARAM NAME = CODEBASE VALUE = ".">
<PARAM NAME = NAME VALUE = "MyApplet" >
<PARAM NAME = ARCHIVE VALUE = "MyTestApplet.jar" >
<PARAM NAME = "type"
VALUE="application/x-java-applet;jpi-version=1.3.1_08">
<PARAM NAME = "scriptable" VALUE="true">

</OBJECT>

Two thoughts:

1) What does the Java console say? In Internet Explorer, choose the menu
Tools / Sun Java console or the equivalent.

2) If your project is urgent, and you don't have time to look for
solutions, can you use the applet as an interface to the Java object, like

document.myApplet.method3( ... );

with:

public void method3(boolean param)
{
IMyInteface2 result = new MyJavaObject2();
return result.method3();
}

I would rather try to find why the first solution doesn't work, but this
one is worth a test.

HTH,

Laurent
 
E

Eyal

Hi,

Thanks for your try, but I think I found the reason...apparently it's
a bug of the java plugin 1.3.1 for IE (bug reference Id: 4528785)

Regards,

Eyal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top