It is not currently very easy to access sub-controllers from a root controller. This makes it difficult to use a controller to open and populate a dialog, for example.
The proposed solution is to map nested controller instances directly to including controller fields, like we currently do with namespace values. For example, if a main FXML document looks like this:
Code:
1 2 3 4 5 6
|
<VBox fx:controller="com.foo.MyMainController">
...
<fx:include fx:id="myInclude" source="my_include.fxml"/>
...
</VBox> |
The document's controller might look like this (the root element of the include is assumed to be a HBox with a controller of type MyIncludeController):
Code:
1 2 3 4 5 6
| public class MyMainController extends Controller {
@FXML private HBox myInclude;
@FXML private MyIncludeController myIncludeController;
...
} |
When initialize() is called, myInclude would contain the root element from "my_include.fxml", and myIncludeController would contain the include's controller, allowing the including code to easily interact with the included controller.