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

Support injection of components read from a declarative file #206

Open
Artur- opened this issue Jun 30, 2017 · 1 comment
Open

Support injection of components read from a declarative file #206

Artur- opened this issue Jun 30, 2017 · 1 comment

Comments

@Artur-
Copy link
Member

Artur- commented Jun 30, 2017

vaadin/spring#193 added support for Vaadin Spring to create components in a design as Spring beans. The same thing would be needed for CDI so you can inject the application components instead of always creating them using new MyComponent

@Artur-
Copy link
Member Author

Artur- commented Jul 5, 2017

This seems to work but I hope there is a better way:

	Design.setComponentFactory(new DefaultComponentFactory() {

			@Override
			public Component createComponent(String fullyQualifiedClassName, DesignContext context) {
				Class<? extends Component> componentClass = resolveComponentClass(fullyQualifiedClassName, context);

				Instance<? extends Component> managedComponent = CDI.current().select(componentClass);
				if (!managedComponent.isAmbiguous() && !managedComponent.isUnsatisfied()) {
					// Injectable, still not clear if the correct class will be
					// used (e.g. componentClass might be Grid<Foo> and
					// MyOwnGrid might be injected, if that happens to exist in
					// the project
					Component component = managedComponent.get();
					if (component.getClass() == componentClass) {
						return component;
					}
				}

				return super.createComponent(fullyQualifiedClassName, context);
			}
		});

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

No branches or pull requests

1 participant