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

Scopes: context doesn't get injected when custom view model is used #426

Closed
sideisra opened this issue Aug 4, 2016 · 1 comment
Closed
Labels
Milestone

Comments

@sideisra
Copy link
Contributor

sideisra commented Aug 4, 2016

I have a view that gets loaded via the FluentViewLoader and contains a @InjectContext annotation because this view has to load another view. When loading the view i pass an existing view model instance to the FluentViewLoader which inhibits the injection of the context into the view. As a result the context field is null when loading the sub view.

FluentViewLoader.fxmlView(viewType).context(context).viewModel(vm).load()

I debugged through the code and identified ControllerFactoryForCustomViewModel as the most likely cause. This Factory injects the context when the custzom view model hasn't been injected in a prior call. So in the first call the context doen't get injected into the view.

private static class ControllerFactoryForCustomViewModel implements Callback<Class<?>, Object> {
 ...
 @Override
 public Object call(Class<?> type) {
  Object controller = DependencyInjector.getInstance().getInstanceOf(type);

  if (controller instanceof View) {
   View codeBehind = (View) controller;
   if (!customViewModelInjected) {
    ResourceBundleInjector.injectResourceBundle(customViewModel, resourceBundle);
    ResourceBundleInjector.injectResourceBundle(codeBehind, resourceBundle);
    ViewLoaderReflectionUtils.injectViewModel(codeBehind, customViewModel);
    customViewModelInjected = true;
    return codeBehind; // returns the code behind without context injected
   }
   handleInjection(codeBehind, resourceBundle, context); //happens only in subsequent calls
  }
  return controller;
 }
}
@manuel-mauky
Copy link
Collaborator

Hi denny, thanks for the report.
I will work on this next week.

manuel-mauky added a commit that referenced this issue Aug 9, 2016
When an existing ViewModel instance is provided to the FluentViewLoader, the context isn't injected into the Root view.
@manuel-mauky manuel-mauky added this to the 1.6.0 milestone Aug 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants