title: Set FXML properties of custom type as attributes for custom javafx component
body: <p>I created custom JavaFX component as described in <a href="http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm" rel="nofollow noreferrer">http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm</a>.</p>
  
  <pre><code>// Component.fxml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.layout.VBox?&gt;
  &lt;fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml"&gt;
      &lt;Label fx:id="label"/&gt;
  &lt;/fx:root&gt;
  
  // Component.java
  public class Component extends VBox {
  
      private final Entity entity;
      @FXML private Label label;
  
      public Component(@NamedArg("entity") Entity entity) {
          this.entity = entity;
          FXMLLoader fxmlLoader = new FXMLLoader();
          fxmlLoader.setLocation(Component.class.getResource("/Component.fxml"));
          fxmlLoader.setRoot(this);
          fxmlLoader.setController(this);
  
          try {
              fxmlLoader.load();
          } catch (IOException exception) {
              throw new RuntimeException(exception);
          }
      }
  
      @FXML
      private void initialize() {
          label.textProperty().set(this.entity.toString());
      }
  }
  </code></pre>
  
  <p>Now i import it into root layout (custom component too).</p>
  
  <pre><code>// Root.fxml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import foo.bar.javafx.Component?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;fx:root type="javafx.scene.layout.AnchorPane"xmlns:fx="http://javafx.com/fxml"&gt;
  // TODO How to pass entity?
  &lt;Component entity=?&gt;
  &lt;/Component&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>// Root.java
  public class Root extends AnchorPane {
  
      public Root() {
          FXMLLoader fxmlLoader = new FXMLLoader();
          fxmlLoader.setLocation(Root.class.getResource("/Root.fxml"));
          fxmlLoader.setRoot(this);
          fxmlLoader.setController(this);
  
          try {
              fxmlLoader.load();
          } catch (IOException exception) {
              throw new RuntimeException(exception);
          }
      }
  
  }
  </code></pre>
  
  <p>How can i pass entity to Component?
  I know how to pass String - it's just <code>&lt;Component entity="text"&gt;</code>. But how to pass instance of arbitary class?
  P.S. Don't want to use Singleton pattern for this.</p>