By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,496 Members | 1,517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,496 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Eyal wrote:
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
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #2

P: n/a
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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.