title: JavaFX Nested Controllers (FXML <include>)
body: <p>In <a href="http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html#nested_controllers" rel="nofollow noreferrer">this</a> tutorial, there is an example of how to include custom components and use their controllers from the controller of the container.</p>
  <p><em>main_window_content.fxml</em></p>
  <pre><code>&lt;VBox fx:controller=&quot;com.foo.MainController&quot;&gt;
     &lt;fx:include fx:id=&quot;dialog&quot; source=&quot;dialog.fxml&quot;/&gt;
     ...
  &lt;/VBox&gt;
  </code></pre>
  <p><em>MainController.java</em></p>
  <pre><code>public class MainController extends Controller {
      @FXML private Window dialog;
      @FXML private DialogController dialogController;
  
      ..
  </code></pre>
  <p>If the component is included only once, it works fine.
  If the same component is included twice, the controllers are not initialized.
  Both controllers are null.</p>
  <p><em>main_window_content.fxml</em></p>
  <pre><code>    &lt;VBox fx:controller=&quot;com.foo.MainController&quot;&gt;
         &lt;fx:include fx:id=&quot;dialog1&quot; source=&quot;dialog.fxml&quot;/&gt;
         &lt;fx:include fx:id=&quot;dialog2&quot; source=&quot;dialog.fxml&quot;/&gt;
         ...
      &lt;/VBox&gt;
  </code></pre>
  <p><em>MainController.java</em></p>
  <pre><code>    public class MainController extends Controller {
          @FXML private Window dialog1;
          @FXML private DialogController dialogController1;
          @FXML private Window dialog2;
          @FXML private DialogController dialogController2;
  </code></pre>
  <p>Could someone help me to solve the problem?
  Thanks</p>
  <p>This is my FXML loading code. It is executed in the main application method:</p>
  <pre><code>public void start(Stage stage) throws Exception { 
      Parent root = FXMLLoader.load(getClass().getResource(&quot;main_window_content.fxml&quot;));
      stage.setTitle(&quot;FXML Welcome&quot;); 
      stage.setScene(new Scene(root, 300, 275));
      stage.show(); 
  }
  </code></pre>