6 Replies Latest reply: Jun 24, 2013 12:14 PM by Pitt RSS

    Applet's Packages attribute is null

    Pitt
      Hi !

      I'm working on a JavaFX applet for a long time, and today I'm facing a really strange problem.

      The javascript object I get with document.getElementById("APPLET_ID") has no Packages attribute under Windows.
      I run my tests on Windows XP with IE8, FF and Chrome up to date, but it's the same problem under windows 7.

      Under Ubuntu with JRE 7u7 x64, no such problem.

      Here is my test code :

      package test;

      import netscape.javascript.JSObject;
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class Main extends Application {

      private JSObject js;
      TextField tf;
      @Override
      public void start(Stage primaryStage) {
      js = this.getHostServices().getWebContext();
      HBox hb = new HBox();
      Scene s = new Scene(hb, 400, 400);
      tf = new TextField("MAIN");
      primaryStage.setScene(s);
      hb.getChildren().add(tf);
      primaryStage.show();
      runTest();
      }

      public static void main(String[] args) {
      launch(args);
      }

      void runTest(){
      new Thread(new Runnable() {

      @Override
      public void run() {
      try {
      Thread.sleep(5000);
      } catch (InterruptedException e) {
      e.printStackTrace();
      }
      Platform.runLater(
      new Runnable() {

      @Override
      public void run() {
      tf.setText("" + js.eval("document.getElementById('applet_id').Packages == null"));

      }
      }
      );
      }
      }).start();
      }
      }


      Displays "false" under Ubuntu JRE7u7x64 and true under Windows JRE7u21 32bits, with all browsers.

      Anyone knowing this issue..?


      Filed on Jira : https://javafx-jira.kenai.com/browse/RT-30732

      Posted on Stackoverflow : http://stackoverflow.com/questions/16799694/applets-packages-attribute-is-null-google-chrome

      Posted on Oracle's Forums : Applet's Packages attribute is null

      Edited by: Pitt on 31 mai 2013 07:55
        • 1. Re: Applet's Packages attribute is null
          Pitt
          Tested under Ubuntu with JRE7u21x64 : the Packages attribute is null too.

          Please, this is a serious problem, could someone just notice me if this is a all new bug, a deprecated access to Packages (didn't see any clue for this), or a known bug ?
          Thanks in advance.
          • 2. Re: Applet's Packages attribute is null
            gimbal2
            Did you consider that you are perhaps just doing it entirely wrong and need to re-read the documentation, a current version of it? For example, a bit of googling turned up this for me:

            https://blogs.oracle.com/javafx/entry/communicating_between_javascript_and_javafx

            giving the hint that doing javascript communication thingies is done through a different API when using JavaFX.
            • 3. Re: Applet's Packages attribute is null
              Pitt
              Did you consider that you are perhaps just doing it entirely wrong and need to re-read the documentation, a current version of it?

              Yes, else I wouldn't ask : could someone just notice me if this is a all new bug, a deprecated access to Packages (didn't see any clue for this), or a known bug ?

              For example, a bit of googling turned up this for me:
              Thanks really much, indeed I didn't consider googling my keywords................. Unfortunately, this hasn't anything to do with my problem, as the concern of this page is the control of a webengine in a JavaFX application.
              The only way to access JS from an applet in an external browser is by using Application.getHostServices(). Am I wrong ?

              The way to access Packages from hosting page's JS is document.getElementById("myAppId").Packages may not be the good one. But I can't find an equivalent workaround...
              Maybe the obvious workaround can be found looking in mechanisms described in the current JavaFX 2 documentation (you are right on this, reading the current doc is the main point, so I guess you should already have found and read it before teaching me about googling) : http://docs.oracle.com/javafx/2/deployment/javafx_javascript.htm

              BTW, the link to the doc I provide gives us an example :

              var mapApp = document.getElementById("myMapApp");
              if (mapApp != null) {
              //City is nested class. Therefore classname uses $ char
              var city = new mapApp.Packages.testapp.MapApp$City(cityName);
              mapApp.navigateTo(city, mapApp.Packages.testapp.MapApp.ZOOM_STREET);
              return mapApp.currentZipCode;
              }
              return "unknown";

              You'll soon see that it's exactly what I'm trying to do.

              As different JRE7 releases may have unpredictable behaviors, I just wonder :
              * Why is the Packages access unabled only since the last minor releases ? (at least 7u21)
              * Is it a bug or not ? If yes, the documentation should be updated.
              * What is the simplest workaround I can find as I don't want to add 120 methods breaking my model in my Application instance.

              Thank you anyway.
              • 4. Re: Applet's Packages attribute is null
                Pitt
                Another up-to-date doc page talking about this Packages attribute: https://jdk6.java.net/plugin2/liveconnect/#PER_APPLET_PACKAGES (found in previous javafx2 deployment doc page)
                • 5. Re: Applet's Packages attribute is null
                  Pitt
                  Only clue of a change for JRE7u21 on this horrible page : http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html
                  The change is that when mixing priviledged code and sandbox code, warnings should prompt (see http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/mixed_code.html ).
                  With all my tests, there's no warning appearing. Looks like I'm missing a permission to access Packages, even with requesting all-permissions security policy in my JNLP file.
                  • 6. Re: Applet's Packages attribute is null
                    Pitt

                    Looks it's an expected change since 7u21 : http://www.oracle.com/technetwork/java/javase/7u21-relnotes-1932873.html

                     

                    This Packages attribute no more works.

                     

                     

                    So if you need callbacks from your JS to your applet, you must access directly it's methods.

                     

                     

                    And use the Trusted-Library manifest attribute to avoid warnings.

                     

                     

                    But you can't do what you want when using Trusted-Library. For example, if you use Axis2 webservices.

                     

                     

                    So you'll have to do it with Trusted-Only manifest attribute. But this forbids you to call methods from JS.

                     

                     

                    Simple workaround :

                    Have a thread periodically checking a JS callback queue and treat them. It's painful, horrible POJO but it works.

                     

                     

                    So to Oracle :

                    THANKS

                     

                    * for updating online doc

                    * for announcing major changes made in minor releases

                    * for making web integration so easy.

                    * for adding other security checks in u25 that result in 20 seconds gray screen latency

                     

                    Do you know Adobe ? Heard they have pretty good stuff... I'm pissed.