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

Discussion in 'Javascript' started by Eyal, Aug 6, 2003.

  1. Eyal

    Eyal Guest

    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>
     
    Eyal, Aug 6, 2003
    #1
    1. Advertising

  2. Re: Urgent: Calling a method of a java object (getting a booleanparameter) from java script

    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
     
    Laurent Bugnion, GalaSoft, Aug 7, 2003
    #2
    1. Advertising

  3. Eyal

    Eyal Guest

    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
     
    Eyal, Aug 7, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    5,574
  2. J Leonard
    Replies:
    4
    Views:
    12,885
    Mark Space
    Jan 19, 2008
  3. Matt
    Replies:
    5
    Views:
    1,680
  4. why-em-jay

    Calling a method of the calling object ...

    why-em-jay, Sep 15, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    195
    Anno Siegel
    Sep 15, 2005
  5. Metre Meter
    Replies:
    7
    Views:
    458
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page