2013-08-20 42 views
0

我下面從該頁面提供的JavaFX 2教程:的JavaFX 2的Javascript的ReferenceError

http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm

我FXML代碼如下:

<?xml version="1.0" encoding="UTF-8"?> 
<?language javascript?> 
<?import java.lang.*?> 
<?import javafx.geometry.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.layout.AnchorPane?> 
<?import javafx.scene.text.*?> 

<GridPane gridLinesVisible="false" hgap="10.0" vgap="10.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"> 
    <fx:script> 
    function handleSubmit() { 
     actionTarget.setText("Calling the Javascript"); 
    } 
    </fx:script> 
    <children> 
    <Text text="Welcome" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0" GridPane.rowSpan="1" /> 
    <Label text="Username" GridPane.columnIndex="0" GridPane.rowIndex="1" /> 
    <Label text="Password" GridPane.columnIndex="0" GridPane.rowIndex="2" /> 
    <TextField GridPane.columnIndex="1" GridPane.rowIndex="1" /> 
    <PasswordField GridPane.columnIndex="1" GridPane.rowIndex="2" /> 
    <HBox alignment="BOTTOM_RIGHT" GridPane.columnIndex="1" GridPane.rowIndex="4"> 
     <children> 
     <Button onAction="handleSubmit(event);" text="Sign In" /> 
     </children> 
    </HBox> 
    <Text fx:id="actionTarget" GridPane.columnIndex="1" GridPane.rowIndex="6" /> 
    </children> 
    <padding> 
    <Insets bottom="25.0" left="25.0" right="25.0" top="25.0" /> 
    </padding> 
</GridPane> 

但每當我按一下按鈕我得到錯誤:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: javax.script.ScriptException: ReferenceError: "handleSubmit" is not defined in <eval> at line number 1 
Caused by: javax.script.ScriptException: ReferenceError: "handleSubmit" is not defined in <eval> at line number 1 

有人可以告訴我什麼是wr在代碼中? 我在Xubuntu上使用Oracle Java 8 JRE

+1

我在Ubuntu 13.04上用JDK 7試過了,並且可以工作,所以這可能是JDK 8的一個bug。 – Katona

+0

是的,我切換到JDK 7,它的工作。 把它寫成答案,我可以接受它。謝謝 –

回答

3

我在Ubuntu 13.04上用JDK 7試過了,效果很好,所以這可能是一個JDK 8的bug。它以某種方式與JavaScript引擎Nashorn相關,它包含在JDK 8(JDK 7使用的是Mozilla Rhino)中,我認爲this郵件提到了同樣的問題。