Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection of root element #236

Open
sideisra opened this issue May 12, 2015 · 6 comments
Open

Injection of root element #236

sideisra opened this issue May 12, 2015 · 6 comments

Comments

@sideisra
Copy link
Contributor

Hi, would it be possible to inject the root element of a view into the code behind (view) via a special annotation or something?

At the moment I need to know the fx:id of the element I want to inject into the view. But often the root element has no fx:id and I don't want to give it a common fx:id (or I can't force the creator of the fxml to do so ;-)).

I think of something like:

@InjectRoot
Node rootNode;

The injected Node should be the root node of the fxml. When the fxml is included in another fxml it should still be the root node of this fxml and not of the whole scene graph.

@manuel-mauky
Copy link
Collaborator

Given the following example files:

  • MainView.java
  • MainViewModel.java
  • MainView.fxml
  • SubView.java
  • SubViewModel.java
  • SubView.fxml

where SubView.fxml is included into MainView.fxml via fx:include.

When I understand you correctly you want to inject the root Node of SubView.fxml into SubView.java and the root Node of MainView.fxml into MainView.java?

@sialcasa
Copy link
Owner

Would the fx:root mechanism fit to your requirements? With this approach you extend the view from a node. In this case the View is automatically the root container and contains the children.

https://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm

@sideisra
Copy link
Contributor Author

@lestard yes exaxctly :-)
@sialcasa I don't think this mechanisms works for me. I don't want to write my own control.

@sialcasa
Copy link
Owner

The oracle documentation is misleading. You can use this approach to implement custom components not custom controls (control api). I recommend to have a short look on this approach.

@sideisra
Copy link
Contributor Author

The fx:root mechanism works for the fxml that is loaded directly via FluentFXMLLoader but not for included FXML.

@manuel-mauky
Copy link
Collaborator

Maybe this can be implemented with Java 9 LoadListener

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants