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

@InjectViewModel doesn't inject viewModel for Guice AOP-ed views #335

Closed
archislav opened this issue Nov 18, 2015 · 3 comments
Closed

@InjectViewModel doesn't inject viewModel for Guice AOP-ed views #335

archislav opened this issue Nov 18, 2015 · 3 comments

Comments

@archislav
Copy link

For example, we have

public class UserView implements FxmlView<UserViewModel>, Initializable {

@InjectViewModel
private UserViewModel viewModel;

 @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
                                viewModel.getUsers() // here viewModel is null
);

and guice module with interceptor

public class InterceptorModule implements Module {
    @Override
    public void configure(Binder binder) {
            binder.bindInterceptor(
                    Matchers.subclassesOf(UserView.class), Matchers.any(), new MyInterceptor());    
}

ViewLoaderReflectionUtils::getViewModelField returns Optional.empty in this case.

@manuel-mauky
Copy link
Collaborator

Hi archislav,
thanks for reporting. I will take a closer look into this issue next week.
We haven't tried out guice interceptors yet because for our internal projects we mostly use CDI.
Our guice module is based on the fx-guice project. Do you know if interceptors are working there?

@manuel-mauky manuel-mauky added this to the 1.4.1 Bugfix-Release milestone Nov 18, 2015
@archislav
Copy link
Author

Hi, Lestard. I've checked fx-guice - it works fine with interceptors (It also provides FxApplicationThread annotation for executing method in JavaFX thread).

de.saxsys.mvvmfx.internal.viewloader.ViewLoaderReflectionUtils::getViewModelField tries to find @InjectViewModel only in current viewType, but in case of interceptors Guice creates subclass of viewType - that why it can't find such field.

@manuel-mauky
Copy link
Collaborator

Many thanks for your hints. It helped a lot.

With PR #336 I've now changed the getViewModelFields method so that it searches in the whole class hierarchy to find the correct field. A test case with a guice interceptor now runs green.

A snapshot version with this bugfix will be automatically pushed to maven central so you can test it. Use version 1.4.1-SNAPSHOT.
We are planing to release the final 1.4.1. version next week.

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