sider sider - 1 year ago 195
Java Question

Nested controller issue in Java FX

I'm trying to include controller(

) in my main layout (main.fxml). But I get the following error:

Can not set lt.mypackage.controllers.SelectedIssueController field lt.mypackage.controllers.MainController.selectedIssueController to javafx.scene.layout.VBox

Line in main.fxml:

<fx:include fx:id="selectedIssueController" source="controllers/selectedissue.fxml" />

My selectedissue.fxml:

<VBox xmlns="" xmlns:fx="" fx:controller="lt.mypackage.controllers.SelectedIssueController" fillWidth="false" SplitPane.resizableWithParent="false">

Line in

private SelectedIssueController selectedIssueController;

As I understand it injects
object now, but I need
. What is wrong with my current implementation?

Answer Source

The FXMLLoader appends Controller to the fx:id specified in the fx:include element to get the name of the field to inject the controller to. Therefore it should be either:

private SelectedIssueController selectedIssueControllerController;


<fx:include fx:id="selectedIssue" source="controllers/selectedissue.fxml" />

The value injected to the field without the Controller suffix is the value created for the fx:include, i.e. the Object created for the root of the included fxml.

See Nested Ccontrollers on stackoverflow Doc

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download