title: Inject Data with Guice into JavaFX ViewController
body: <p>Today I added Guice to my Java FX Application. The main goal was to replace the singletons I had with Injection and break up dependencies.
  So far everything worked fine, this is the code I have to start a new Scene:</p>
  
  <pre><code>public class App extends Application{
  
  public static void main(String[] args){
      launch(args);
  }
  
  @Override
  public void start(Stage primaryStage) throws Exception {
      final String LANGUAGE_BUNDLE = "myBundlePath";
      final String FXML = "myFXMLPath";
  
      try {
          ResourceBundle resourceBundle = ResourceBundle.getBundle(LANGUAGE_BUNDLE, Locale.GERMAN, this.getClass().getClassLoader());
          FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(FXML), resourceBundle, new JavaFXBuilderFactory(), getGuiceControllerFactory());
          primaryStage.setScene(new Scene(fxmlLoader.load()));
          primaryStage.show();
      }catch (IOException ex) {
          ex.printStackTrace();
      }
  }
  
  private Callback&lt;Class&lt;?&gt;, Object&gt; getGuiceControllerFactory(){
      Injector injector = Guice.createInjector(new GuiceModule());
      return new Callback&lt;Class&lt;?&gt;, Object&gt;() {
          @Override
          public Object call(Class&lt;?&gt; clazz) {
              return injector.getInstance(clazz);
          }
      };
  }
  }
  </code></pre>
  
  <p>My Guice Module looks like this:</p>
  
  <pre><code>public class GuiceModule extends AbstractModule {
  @Override
  protected void configure() {
      bind(ITester.class).to(Tester.class);
      bind(ISecondTest.class).to(SecondTest.class);
  }
  }
  </code></pre>
  
  <p>Please note that i substituted the paths for the ressource bundle and the fxml file as they would have revealed my identity. But loading and everything works, so this shouldn't be a problem ;)</p>
  
  <p>Now the problem is, that I want to instantiate a new view with a button click in a different view. The second view should display a more detailed version of the data in view 1.
  Everything that I need to pass to the second view is an Integer (or int), but I have absolutely no clue on how to do this.</p>
  
  <p>I have the standard FX setup with:</p>
  
  <pre><code>View.fxml (with a reference to the ViewController)
  ViewController.java
  Model.java
  ViewModel.java
  </code></pre>
  
  <p>The <code>ViewController</code> then binds to properties offered by the <code>ViewModel</code>.
  I need the int to choose the correct model.</p>
  
  <p>Everything I could find was about the Annotation <code>@Named</code> but as far as I can see, this wouldn't be usable to inject dynamic data.</p>
  
  <p>Could you please give me a hint what this what I want to do is called?
  Or long story short: How can I inject a variable, chosen by a different view, in a second <code>ViewController</code>, and leaving the rest in the standard FX-way?</p>
  
  <p>Any help appreciated and thanks in advance!</p>
  
  <p>Regards, Christian</p>