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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eyal

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

    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)param eter. 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.inte rfaces;

    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.myOb ject2;

    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.Test Applet;

    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=JavaSc ript>
    function Execute()
    {
    var myApplet = document.myAppl et;
    myApplet.method 3(false);//this one is fine (getting boolean)

    var myJavaObj2 = myApplet.newJav aObject2();
    myJavaObj2.meth od1("Test"); //this one is fine (getting String)
    myJavaObj2.meth od2(1); //this one is fine (getting int)
    myJavaObj2.meth od3(false); //this one fails (getting boolean)
    myJavaObj2.meth od3("false"); //this one fails (getting boolean)
    myJavaObj2.meth od3(0); //this one fails (getting boolean)
    myJavaObj2.meth od3(""); //this one fails (getting boolean)
    }
    </script>

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

    <OBJECT ID="SmartFileCa talog"
    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#Versio n=1,3,1,8">

    <PARAM NAME = CODE VALUE = "name.space.Tes tApplet.class" >
    <PARAM NAME = CODEBASE VALUE = ".">
    <PARAM NAME = NAME VALUE = "MyApplet" >
    <PARAM NAME = ARCHIVE VALUE = "MyTestApplet.j ar" >
    <PARAM NAME = "type"
    VALUE="applicat ion/x-java-applet;jpi-version=1.3.1_0 8">
    <PARAM NAME = "scriptable " VALUE="true">

    </OBJECT>
  • Laurent Bugnion, GalaSoft

    #2
    Re: Urgent: Calling a method of a java object (getting a booleanparamete r) from java script

    Hi,

    Eyal wrote:[color=blue]
    > 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)param eter. 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.inte rfaces;
    >
    > 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.myOb ject2;
    >
    > 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.Test Applet;
    >
    > 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=JavaSc ript>
    > function Execute()
    > {
    > var myApplet = document.myAppl et;
    > myApplet.method 3(false);//this one is fine (getting boolean)
    >
    > var myJavaObj2 = myApplet.newJav aObject2();
    > myJavaObj2.meth od1("Test"); //this one is fine (getting String)
    > myJavaObj2.meth od2(1); //this one is fine (getting int)
    > myJavaObj2.meth od3(false); //this one fails (getting boolean)
    > myJavaObj2.meth od3("false"); //this one fails (getting boolean)
    > myJavaObj2.meth od3(0); //this one fails (getting boolean)
    > myJavaObj2.meth od3(""); //this one fails (getting boolean)
    > }
    > </script>
    >
    > -------------------------
    > Html Code (plug in tag):
    > -------------------------
    >
    > <OBJECT ID="SmartFileCa talog"
    > 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#Versio n=1,3,1,8">
    >
    > <PARAM NAME = CODE VALUE = "name.space.Tes tApplet.class" >
    > <PARAM NAME = CODEBASE VALUE = ".">
    > <PARAM NAME = NAME VALUE = "MyApplet" >
    > <PARAM NAME = ARCHIVE VALUE = "MyTestApplet.j ar" >
    > <PARAM NAME = "type"
    > VALUE="applicat ion/x-java-applet;jpi-version=1.3.1_0 8">
    > <PARAM NAME = "scriptable " VALUE="true">
    >
    > </OBJECT>[/color]

    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.myAppl et.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

    Comment

    • Eyal

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

      Hi,

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

      Regards,

      Eyal

      Comment

      Working...