I have an FXML file that has many controller methods that I send to a regular controller. However, I recently added some small handlers that did very trivial things, and I was wondering if I could do them in javascript in the FXML file itself. However, it looks like I ran into a problem: I cannot find a documented way to get the controller object in javascript. How can I get the controller object in javascript? (and no, I cannot use static methods because I have many such controllers on many objects)
Current code using Java: FXML file:
... <GridPane fx:id="moveOverlay" onMouseClicked="#mouseOverlayClicked" ...> ....
and java controller:
... @FXML private void mouseOverlayClicked(MouseEvent e) { if (e.getClickCount() > 1) { this.enableNestedEditing(); } else if (e.isControlDown()) { this.selectSelf(); } } ...
Desired FXML:
... <fx:script> var controller = [what goes here?]; function mouseOverlayClicked(e) { if (e.getClickCount() > 1) { controller.enableNestedEditing(); else if (e.isControlDown()) { controller.selectSelf(); } </fx:script> ... <GridPane fx:id="moveOverlay" onMouseClicked="mouseOverlayClicked" ...> ...
and no corresponding event handler in the java class (except for other methods)
source share