title: Passing parameters between two JavaFX controllers
body: <p>I want to click a column and send the cell index to a new stage. But I can't pass my parameter (<code>int clickIndex</code>) to another controller <code>EditClientController</code>. I've tried everything, but it still does not work. </p>
  
  <p><strong>MainController</strong></p>
  
  <pre><code>package controller;
  
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.fxml.Initializable;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.scene.control.*;
  import javafx.scene.control.cell.PropertyValueFactory;
  import javafx.scene.input.MouseEvent;
  import javafx.scene.text.Text;
  import javafx.stage.Stage;
  import javafx.util.Callback;
  import model.Table;
  
  import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.net.URL;
  import java.util.ResourceBundle;
  
  public class MainController implements Initializable {
  
      @FXML
      TableView&lt;Table&gt; tableID;
      @FXML
      TableColumn iLp;
      @FXML
      TableColumn iCity;
      @FXML
      TableColumn iDeviceName;
      @FXML
      TableColumn iSerialNumber;
      @FXML
      TableColumn iCompanyName;
      @FXML
      TableColumn iContact;
      @FXML
      TableColumn iSellDate;
      @FXML
      TableColumn iWarranty;
      @FXML
      TableColumn iNextReview;
      @FXML
      TableColumn iWarrantyTrue;
      @FXML
      Button addButton;
      @FXML
      ComboBox warrantyLength;
      @FXML
      ComboBox nextReview;
      @FXML
      ComboBox warrantyTrue;
  
  
      //Define variables
      private int iNumber= 1;
      public int clickIndex;
  
  
      //Create table data
       ObservableList&lt;Table&gt; data = FXCollections.observableArrayList();
  
      //Combo box
      final ObservableList warranty = FXCollections.observableArrayList("---",12,24,36);
      final ObservableList review = FXCollections.observableArrayList("---","tydzień","miesiąc","2 miesiące", "6 miesięcy");
      final ObservableList warrantyTF = FXCollections.observableArrayList("---","tak","nie");
  
  
  
      Callback&lt;TableColumn, TableCell&gt; cellFactory2 =
              new Callback&lt;TableColumn, TableCell&gt;() {
                  public TableCell call(TableColumn p) {
  
                      final TableCell cell = new TableCell&lt;Table, Integer&gt;() {
                          @Override
                          public void updateItem(Integer item, boolean empty) {
                              super.updateItem(item, empty);
                              setText(empty ? null : getString());
                              setGraphic(null);
                          }
  
                          private String getString() {
                              return getItem() == null ? "" : getItem().toString();
                          }
                      };
  
                      cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler&lt;MouseEvent&gt;() {
                          @Override
                          public void handle(MouseEvent event) {
                              if (event.getClickCount() &gt; 1) {
                                  clickIndex=cell.getIndex();
                                  try {
                                      FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("editClient.fxml"));
                                      Parent root1 = (Parent) fxmlLoader.load();
                                      Stage stage = new Stage();
                                      stage.setTitle("Edytuj klienta");
                                      stage.setScene(new Scene(root1));
                                      stage.show();
                                  } catch(Exception e) {
                                      e.printStackTrace();
                                  }
                              }
                          }
                      });
                      return cell;
                  }
              };
  
      Callback&lt;TableColumn, TableCell&gt; cellFactory =
              new Callback&lt;TableColumn, TableCell&gt;() {
                  public TableCell call(TableColumn p) {
  
                      final TableCell cell = new TableCell&lt;Table, String&gt;() {
                          private Text text;
                          @Override
                          public void updateItem(String item, boolean empty) {
                              super.updateItem(item, empty);
                              text = new Text(item);
                              text.setWrappingWidth(100);
                              setGraphic(text);
                          }
  
                          private String getString() {
                              return getItem() == null ? "" : getItem().toString();
                          }
                      };
  
                      cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler&lt;MouseEvent&gt;() {
                          @Override
                          public void handle(MouseEvent event) {
                              if (event.getClickCount() &gt; 1) {
                                  clickIndex = cell.getIndex();
                                  try {
                                      FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("editClient.fxml"));
                                      Parent root1 = (Parent) fxmlLoader.load();
                                      Stage stage = new Stage();
                                      stage.setTitle("Edytuj klienta");
                                      stage.setScene(new Scene(root1));
                                      stage.show();
                                  } catch(Exception e) {
                                      e.printStackTrace();
                                  }
                              }
                          }
                      });
                      return cell;
                  }
              };
  
      public void setClickedIndex(int click){
          this.clickIndex=click;
      }
  
      public int getClickIndex(){
          return clickIndex;
      }
  
  
      //Plik
      public void openFile() {
          FileReader plik = null;
          int tab0=1;
          int tab7=0;
          String tab9=null;
          try {
              plik = new FileReader("dane.txt");
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
          BufferedReader bfr = new BufferedReader(plik);
          String linia = null;
  
          try {
              while ((linia = bfr.readLine()) != null) {
                  String[] tab = linia.split(";");
                  tab7=Integer.parseInt(tab[7]);
                  if(tab.length==10) {
                      if(tab[9].contains(tab[8])){
                          tab9="Tak";
                      }else{
                          tab9="Nie";
                      }
                  }
                  Table tablica = new Table(tab0++, tab[1], tab[2], tab[3], tab[4], tab[5], tab[6], tab7, tab[8], tab9);
                  data.add(tablica);
  
              }
          } catch (Exception e) {
              System.out.println("BŁĄD ODCZYTU Z PLIKU!");
              System.exit(2);
          }
          try {
              plik.close();
          } catch (IOException e) {
              System.out.println("BŁĄD PRZY ZAMYKANIU PLIKU!");
              System.exit(3);
          }
      }
      public void setData(ObservableList&lt;Table&gt; newData){
         data=newData;
      }
  
      public ObservableList&lt;Table&gt; getData(){
          return data;
      }
  
      public void pressButton(ActionEvent event) throws Exception {
          try {
              FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("addClient.fxml"));
              Parent root1 = (Parent) fxmlLoader.load();
              Stage stage = new Stage();
              stage.setTitle("Dodaj klienta");
              stage.setScene(new Scene(root1));
              stage.show();
          } catch(Exception e) {
              e.printStackTrace();
          }
      }
  
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
         openFile();
  
          iLp.setCellValueFactory(new PropertyValueFactory&lt;Table, Integer&gt;("rLp"));
          iCity.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rCity"));
          iDeviceName.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rDeviceName"));
          iSerialNumber.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rSerialNumber"));
          iCompanyName.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rCompanyName"));
          iContact.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rContact"));
          iSellDate.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rSellDate"));
          iWarranty.setCellValueFactory(new PropertyValueFactory&lt;Table, Integer&gt;("rWarranty"));
          iNextReview.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rNextReview"));
          iWarrantyTrue.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rWarrantyTrue"));
  
  
          iLp.setCellFactory(cellFactory2);
          iCity.setCellFactory(cellFactory);
          iDeviceName.setCellFactory(cellFactory);
          iSerialNumber.setCellFactory(cellFactory);
          iCompanyName.setCellFactory(cellFactory);
          iContact.setCellFactory(cellFactory);
          iSellDate.setCellFactory(cellFactory);
          iWarranty.setCellFactory(cellFactory2);
          iNextReview.setCellFactory(cellFactory);
          iWarrantyTrue.setCellFactory(cellFactory);
  
          tableID.setItems(data);
  
          //comboboxy
          warrantyLength.setItems(warranty);
          warrantyLength.getSelectionModel().select(0);
          nextReview.setItems(review);
          nextReview.getSelectionModel().select(0);
          warrantyTrue.setItems(warrantyTF);
          warrantyTrue.getSelectionModel().select(0);
      }
  
  }
  </code></pre>
  
  <p><strong>EditClientController</strong></p>
  
  <pre><code>package controller;
  
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.control.ComboBox;
  import javafx.scene.control.TextField;
  
  import java.net.URL;
  import java.util.ResourceBundle;
  
  /**
   * Created by Krzysztof on 2015-01-14.
   */
  public class EditClientController implements Initializable {
  
      @FXML
      ComboBox warrantyLength;
      @FXML
      TextField city;
      public int index;
  
  
      //Combo box dla okresu gwarancyjnego
      final ObservableList warranty = FXCollections.observableArrayList("---", 12, 24, 36);
  
      public void setIndex(int index){
          this.index=index;
      }
      public int getIndex(){
          return index;
      }
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
         // city.setText(tablica.get(index).getRCity());
          warrantyLength.setItems(warranty);
          warrantyLength.getSelectionModel().select(0);
  
      }
  }
  </code></pre>