Issue
The FXMLLoader does not recognize the <?language javascript?>
directive when trying to process an fxml script (see below). The error message is "Page language not specified". My fxml is like follows (actual code ommitted for brevity):
<?language javascript?>
<!-- differnet includes -->
...
<!-- actual fxml -->
<StackPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="com.xxx.xxx.MainViewController"
prefWidth="1200">
...
<!-- somewhere in the middle of the fxml code -->
<fx:script>
function clearTool1() {
tool1.setValue(null);
}
</fx:script>
...
<StackPane/>
I have investigated a bit and found out that the ScriptEngineManager
class of javafx actually does not see any script engines. In particular, in its getEngineByName
method, the collection of ScriptEngineFactory
is empty, so it does not find any javascript engine and throws the exception later on. I will not go into details on this since the goal is not to debug javafx source code but I thought it could be useful as a hint.
Do you have any idea why the scripting language directive is not recognized although the fxml and everything else is written correctly?
Solution
Of course, you have to include the scripting engine implementation into your pom...
<dependency>
<groupId>org.openjdk.nashorn</groudId>
<artifactId>nashorn-core</artifactId>
<version>15.0</version>
</dependency>
Thanks to @Pointy and @James_D for giving a hint regarding that.
Answered By - Serhii
Answer Checked By - Cary Denson (JavaFixing Admin)