title: JavaFX correct way to open and close a Stage multiple times
body: <p><strong>Problem:</strong>
  I am working on a client server desktop application using JavaFx, everything works fine except that I have found that when I open a new stage clicking a button on the Home Page, the new Stage loads data only the first time I open it. The initialize method of the new stage sends a request to server and receives back an object whose fields are loaded on the new stage. None exception is thrown, the server always send the object correctly (tested by printing its vales on console).</p>
  <p>My suspicion is that when I click the button to open a new stage, it creates a new instance of the FXML Loader each time. What I don't get is dued to the fact that the execution cycle is always the same both the first time I open the stage and the following ones.</p>
  <p>I finally tried to insert a button in the second window which, when clicked, loads the object on the window, and this works correctly also when I open the window multiple times, but obviously I don't like this solution, which would force the user to click the button to retreive data.</p>
  <p>Here is the HomePage Controller method that allows to open the new stage:</p>
  <pre><code>@FXML
  void showSecondView(MouseEvent event) throws IOException {
  
  
                 
                  FXMLLoader loader = new FXMLLoader();
  
                  loader.setLocation(Main.class.getResource(&quot;/View_FXML/generaRichiesta.fxml&quot;));
                  Pane secondPageLayout = loader.load();
                  SecondController secCon = loader.getController();
               
  
                  stage = new Stage();
                  stage.setScene(new Scene(secondPageLayout));
  
               
                  stage.setTitle(&quot;Second Stage&quot;);
  
  
                  stage.show();
  
  }
  </code></pre>
  <p>Here is the Initialize method for the Second Stage</p>
  <pre><code>public void initialize(URL url, ResourceBundle resourceBundle) {
                           
          //sending request to server and calling the following function to update the
          //view withe the received object
          
         Platform.runLater(
              () -&gt; {
                 //setting the view node &quot;textField&quot; with the object received from server
                 //if I print this value on console I always get the object correctly but
                 //it is loaded only the first time. When i call this function from a button it always
                 //works but I should do it manually
                 textField.setText().receivedObject.toString(); 
                
              }
          );
  }
  </code></pre>
  <p>I really don't get what the problem could be, I think it may be because when  I create every time and FXMLLoader object.</p>
  <p>Any suggestions?</p>
  <p>Thanks</p>