FXML Scripting and Nashorn Error Messages

TA Hubbard tahubbard at fxmlguide.com
Wed Jul 17 09:55:57 PDT 2013


Dear Sirs;

A fundamental feature of JavaFX's FXML is scripting.  The process is 
simple; add the <?language javascript?> 'processing instruction' to 
standard FXML processing instructions (JavaFX import declarations or 
statements) then script.

As you know, some of the scripting languages include JavaScript, JavaFX, 
and DSL's such as Groovy, Clojure, etc.

Unfortunately, since build JDK8_91, if the above language processing 
instruction is included within an FXML document, Nashorn produces 
FXMLLoader _null pointer error_ messages during compilation with 
NetBeans (Windows Vista).  Since JDK8_97, if nashorn.jar is manually 
included as a separate library within the application, no null pointer 
error messages are produced but we should not have to include a separate 
jar for FXML scripting.

On the other hand, with the nashorn.jar manually included, the following 
sample button from Oracle's 'Introduction To FXML', works just fine:

<Button text="Click Me!" onAction="java.lang.System.out.println('You 
clicked me!');"/>
This prints "You clicked me!" to the console.

However, use of the <fx:script> tag to run a second sample from 
'Introduction To FXML' produces multiple error messages:
<fx:script>
     importClass(java.lang.System);
     function handleButtonAction(event) {
        System.out.println('You clicked me!');
     }
</fx:script>
<Button text="Run JavaScript function by clicking" 
onAction="handleButtonAction(event);"/>

The first error message produced is on JavaFX's own 'importClass' 
method, as follows:
ReferenceError: "importClass" is not defined in <eval> at line number 2 
... (I have found no reference where importClass has been deprecated)

A second error message begins with the following:
Caused by: javax.script.ScriptException: ReferenceError: 
"handleButtonAction" is not defined in <eval> at line number 1 at 
jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:426) 
...

Finally, doing a simple JavaFX object method call within FXML produces 
error messages on the following:
<Button fx:id="vanish" text="This button should vanish" />
<Button text="Press to remove the above button" 
onAction="vanish.setVisible(false)"/>

One error message begins like this:
Caused by: javax.script.ScriptException: ReferenceError: "vanish" is not 
defined in <eval> at line number 1 at 
jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:426) 
...

I hope you can restore these capabilities soon with Nashorn since they 
are central to advanced FXML scripting, and since they apparently worked 
well with the other JavaFX JavaScript engine.  I was instructed to do a 
Jira on this, but I will wait your response first.

Thank you.

TAH





More information about the nashorn-dev mailing list