Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8123522

not possible to call functions defined in javascript from fxml anymore

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 8
    • 8
    • javafx
    • None

    Description

      consider the following code which worked with javafx 2.2.x:

      Controller:

      public class SomeController {

        @FXML
        public void print(String s){
          System.out.println("from javascript: "+s);
        }
      }

      FXML:

      <?xml version="1.0" encoding="utf-8"?>

      <?language javascript?>
      <?import javafx.scene.layout.VBox?>
      <?import javafx.scene.control.Button?>

      <VBox xmlns:fx="http://javafx.com/fxml"
            fx:controller="fxmltest.SomeController">
        <fx:script>
          function buttonClicked(text) {
          controller.print(text);
          }
        </fx:script>
        <children>
          <Button text="John Doe" onAction="buttonClicked('hi')"/>
        </children>
      </VBox>

      this was the only way to pass parameters from fxml to its controller in an onAction method and it was extremely convenient. this code is adaped from the javafx fxml tutorial at http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#script_event_handlers
      This code fails in javafx 8 (newest EAP):

      Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: javax.script.ScriptException: ReferenceError: "buttonClicked" is not defined in <eval> at line number 1
      at javafx.fxml.FXMLLoader$ScriptEventHandler.handle(FXMLLoader.java:1536)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.event.Event.fireEvent(Event.java:203)
      at javafx.scene.Node.fireEvent(Node.java:7996)
      at javafx.scene.control.Button.fire(Button.java:184)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:183)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:91)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:84)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:203)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3622)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3453)
      at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3405)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1697)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2473)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:312)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:237)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:354)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:514)
      at com.sun.glass.ui.View.notifyMouse(View.java:877)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
      at java.lang.Thread.run(Thread.java:724)
      Caused by: javax.script.ScriptException: ReferenceError: "buttonClicked" is not defined in <eval> at line number 1
      at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:426)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:410)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:392)
      at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:139)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
      at javafx.fxml.FXMLLoader$ScriptEventHandler.handle(FXMLLoader.java:1534)
      ... 47 more
      Caused by: <eval>:1 ReferenceError: "buttonClicked" is not defined
      at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:66)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:328)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:300)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:287)
      at jdk.nashorn.internal.runtime.ScriptObject.noSuchProperty(ScriptObject.java:1976)
      at jdk.nashorn.internal.runtime.ScriptObject.noSuchMethod(ScriptObject.java:1939)
      at jdk.nashorn.internal.runtime.ScriptObject.findGetMethod(ScriptObject.java:1691)
      at jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1603)
      at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:75)
      at jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:176)
      at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124)
      at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:138)
      at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:229)
      at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
      at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:518)
      at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:202)
      at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:366)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:408)
      ... 51 more
      Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: javax.script.ScriptException: ReferenceError: "buttonClicked" is not defined in <eval> at line number 1
      at javafx.fxml.FXMLLoader$ScriptEventHandler.handle(FXMLLoader.java:1536)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.event.Event.fireEvent(Event.java:203)
      at javafx.scene.Node.fireEvent(Node.java:7996)
      at javafx.scene.control.Button.fire(Button.java:184)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:183)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:91)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:84)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:203)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3622)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3453)
      at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3405)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1697)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2473)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:312)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:237)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:354)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:514)
      at com.sun.glass.ui.View.notifyMouse(View.java:877)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
      at java.lang.Thread.run(Thread.java:724)
      Caused by: javax.script.ScriptException: ReferenceError: "buttonClicked" is not defined in <eval> at line number 1
      at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:426)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:410)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:392)
      at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:139)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
      at javafx.fxml.FXMLLoader$ScriptEventHandler.handle(FXMLLoader.java:1534)
      ... 47 more
      Caused by: <eval>:1 ReferenceError: "buttonClicked" is not defined
      at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:66)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:328)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:300)
      at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:287)
      at jdk.nashorn.internal.runtime.ScriptObject.noSuchProperty(ScriptObject.java:1976)
      at jdk.nashorn.internal.runtime.ScriptObject.noSuchMethod(ScriptObject.java:1939)
      at jdk.nashorn.internal.runtime.ScriptObject.findGetMethod(ScriptObject.java:1691)
      at jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1603)
      at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:75)
      at jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:176)
      at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124)
      at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:138)
      at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:229)
      at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
      at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:518)
      at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:202)
      at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:366)
      at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:408)

      Attachments

        Activity

          People

            msladecek Martin Sládeček
            srheinnecjfx Sebastian Rheinnecker (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: