You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
manuel-mauky
changed the title
CDI: ViewModels are created twice in some situations.
Two ViewModel instances are created when the view has no field for the ViewModel
Feb 19, 2015
After a little investigation I found out that this is not a problem specific to CDI but in the main module.
When the View has no field defined for the ViewModel and no injection is happening, two instances of the ViewModel are created.
When a View is requested by the FXMLLoader we create a new ViewModel instance (or take one from DI) and are trying to inject it into the View. If the view has no Field defined for the ViewModel, nothing happens.
A view steps later we try to get the ViewModel instance from the View so we can provide it in the returned ViewTuple. If at this point there is no field in the View, we are creating a new ViewModel instance.
The solution is to create a new ViewModel instance in the ControllerFactory only when there is a Field defined.
When using the CDI module under some conditions there are two instances of the ViewModel created when we would expect to have only one.
This sounds similar to #124
The text was updated successfully, but these errors were encountered: