title: Getting a variable from a FXML to an imported FXML
body: <p>I'm currently doing a Java (+ using MySQL) application for my studies : an Database for an Hopital</p>
  
  <p>I code my interface using JavaFX.
  I have a Main FXML(for the general view) where I have tabs and in each tab I import another FXML using (fx:include). So that each module of my application has his own Controller and own designed View.</p>
  
  <p>How can pass a variable from the main Controller to the others controllers?</p>
  
  <p>Thanks!
  Edit : Let me show you my code</p>
  
  <p>So first there it's the class in which I load my fxml (I have on window of Connexion first and if the informations required for the connexion are ok I load the fxml Main with the main interface) And I set the connexion (THE VARIABLE I NEED TO SEND) that I got from my fxml Connexion to the FXML Main </p>
  
  <pre><code>public class MainApp extends Application {
  
  private Stage primaryStage;
  private Connection conn;
  MainController controllermain = new MainController();
  //ConnexionController controllerconnex;
  
  @Override
  public void start(Stage primaryStage) throws Exception {
      this.primaryStage = primaryStage;
      this.primaryStage.setTitle("BASE DE L'HOPITAL DU ZOB");
      showConnexion();
  }
  
  public void showConnexion() {
      try {
  
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(MainApp.class.getResource("Connexion.fxml"));
          Parent page = (AnchorPane) loader.load();
          Scene scene = new Scene(page);
  
          primaryStage.setScene(scene);
          primaryStage.show();
  
          ConnexionController controller = loader.getController();
          controller.setMainApp(this);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  public void showMainApp(Connection conn) {
      try {
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(MainApp.class.getResource("Main.fxml"));
          AnchorPane page = (AnchorPane) loader.load();
          Scene scene = new Scene(page);
          primaryStage.setScene(scene);
          primaryStage.show();
          this.conn = conn;
  
          controllermain = loader.getController();
          controllermain.setMainApp(this);
          controllermain.setConnexion(conn); // I want to send the variable conn to the others
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      launch(args);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Then this is my Main Controller and you can see that I get the variable connexion only with the set method and then I can send it the the other controller</p>
  
  <pre><code>public class MainController implements Initializable {
  
  
  private MainApp mainApp;
  private Button retour;
  protected Connection conn;
  
  
  FXML AchorPane ;
  
     public MainController() {
  }
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
  
  }    
  
  
   public void setMainApp(MainApp mainApp) {
      this.mainApp = mainApp;
  
  
  }
  
   public void setConnexion(Connection conn){
  
   this.conn=conn;
  
       }
  public void handleRetour(){
                         mainApp.showConnexion();
  
  
      }
   }     
  
  
  }
  </code></pre>