Hi,
how can I use CDI on domain objects?
I’ve successfully set up the CDI AddOn and already using @CDIUI, the application runs fine.
Now I tried the following, but the object is never injected. Why?
@UiScoped
class UserSettings;
@UiScoped
class User {
@Inject
@New
private UserSettings settings; //always null
}
This is my servlet:
@CDIUI
public class MyApp extends UI {
@WebServlet(value = "/*", asyncSupported = true,
initParams = { @WebInitParam(name = Constants.SERVLET_PARAMETER_UI_PROVIDER, value = "com.vaadin.cdi.CDIUIProvider")})
@VaadinServletConfiguration(productionMode = false, ui = MyApp.class, widgetset = "my.app.AppWidgetSet")
public static class Servlet extends VaadinServlet {}
}
I also tried to inject a vaadin component in a class (same as what has been done here:
https://github.com/vaadin/cdi/blob/master/vaadin-cdi-example/src/main/java/com/vaadin/cdi/example/view/InjectableLayout.java
), but also this gives me always a NPE:
class MyMenuBar extends CustomComponent {
@Inject
@New
private MenuBar menuBar; //is always null!
}