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

Can't access Viewmodel after Include. #190

Open
sialcasa opened this issue Mar 16, 2015 · 8 comments
Open

Can't access Viewmodel after Include. #190

sialcasa opened this issue Mar 16, 2015 · 8 comments

Comments

@sialcasa
Copy link
Owner

Can't access Viewmodel after Include.

@FXML
private Node import_createPerson;

@FXML
private CreatePersonView import_createPersonController;

//SHOULD WORK --> Or other solution
@FXML
private CreatePersonViewModel import_createPersonViewModel;

@sialcasa
Copy link
Owner Author

Michael reported, that our ViewLoader does not construct the ViewModels of fx:include views. This is a serious bug.

@manuel-mauky
Copy link
Collaborator

This sounds like a misconfiguration or some other special case because actually the usage of fx:include does work without problems. We have plenty examples that demonstrate this. For example the contacts-example consists of many sub views that are orchestrated via fx:include.

There is also a test case that verifies exactly this use case with fx:include here.

Anyway, I think the bug report is not directly related to this feature request.
If you still think that there is a problem with fx:include can you please file a new issue and provide more information of your use case so we may find out what the problem is.

@mthiele
Copy link

mthiele commented Apr 1, 2015

This has been a misunderstanding. I reported that I wanted exactly the behaviour as described in the original comment (i.e., get a viewmodel of a nested view injected into the parent view).
The viewmodel was constructed as it should.

@sialcasa sialcasa added this to the 1.1.0 milestone Apr 2, 2015
@manuel-mauky
Copy link
Collaborator

The injection of the subview via the "controller" naming convention is done by JavaFX internals and not by mvvmFX.
To get the viewModels of included subviews we can try to enhance the ControllerFactories in FxmlViewLoader.java but this will be a big change and may need a bigger refactoring of the FxmlViewLoader.

@sialcasa
Copy link
Owner Author

sialcasa commented Apr 3, 2015

@lestard Sounds tuff, other ideas?

@manuel-mauky
Copy link
Collaborator

The idea to enhance the ControllerFactory won't work because we don't know the fx:id in the controller factory method. Therefore we can't distinguish between viewmodels of the same type.

@manuel-mauky
Copy link
Collaborator

To implement this feature we would need to patch the FXMLLoader. The FXMLLoader has inner classes for all types of elements that can occure in a fxml file. We would need to patch the "IncludeElement" class that can be found here. On line 1015 begins the code block that is responsible for the injection of the Controller class via the *Controller naming convention. Similar to this we would need to add our own naming convention for the viewModels.

The FXMLLoader isn't marked as final so we could create our own sub class. Nevertheless, the IncludeElement inner class is private and therefore we can't simply replace it without some sort of "magic" that could lead to compatibility problems in future versions of JavaFX.

@manuel-mauky manuel-mauky modified the milestones: 1.2.0, 1.1.0 Apr 9, 2015
@manuel-mauky
Copy link
Collaborator

This issue has a similar idea to #215

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