title: Vaadin 7 CDI, inject EJB in View
body: <pre><code>@Local
  public interface MediaManagerService {
  
  @Stateless
  public class MediaManagerServiceImpl implements MediaManagerService, Serializable {
  
      private static final long serialVersionUID = -3484115607954217804L;
  
      @PersistenceContext(name="MediaManagerPersistenceUnit", 
                          unitName="MediaManagerPersistenceUnit")
      private EntityManager _em;
  </code></pre>
  
  <p>I can inject service successful in UI by this code:</p>
  
  <pre><code>@CDIUI
  public class MainUI extends ManagedUI {
      private Navigator _navigator;
  
      @Inject
      private CDIViewProvider _viewProvider;
  
      @Inject
      private MediaManagerService _service;
  </code></pre>
  
  <p>But in the view, it always throws null.</p>
  
  <pre><code>@CDIView("MovieView")
  public class MovieView extends ManagedComponent implements View {
      public static final String NAME = "MovieView";
  
      @Inject
      private MediaManagerService _service;
  </code></pre>
  
  <p>The _service always throws null in the View.
  This is from the console:</p>
  
  <pre><code>10:17:25,052 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Attempting to retrieve view name from string ""
  10:17:25,052 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Looking for view with name ""
  10:17:25,053 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) com.tien113.ui.MovieView is annotated, the viewName is "MovieView"
  10:17:25,053 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) com.tien113.ui.LoginView is annotated, the viewName is ""
  10:17:25,053 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Bean Managed Bean [class com.tien113.ui.LoginView] with qualifiers [@Any @Default] with viewName "" is one alternative
  10:17:25,054 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Attempting to retrieve view with name ""
  10:17:25,054 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Looking for view with name ""
  10:17:25,054 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) com.tien113.ui.MovieView is annotated, the viewName is "MovieView"
  10:17:25,055 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) com.tien113.ui.LoginView is annotated, the viewName is ""
  10:17:25,055 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Bean Managed Bean [class com.tien113.ui.LoginView] with qualifiers [@Any @Default] with viewName "" is one alternative
  10:17:25,055 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Created new creational context for current view org.jboss.weld.context.CreationalContextImpl@5182605a
  10:17:25,071 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-5) Returning view instance com.tien113.ui.LoginView@6713e65a
  10:17:27,104 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Attempting to retrieve view name from string "MovieView"
  10:17:27,104 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Looking for view with name "MovieView"
  10:17:27,104 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) com.tien113.ui.MovieView is annotated, the viewName is "MovieView"
  10:17:27,104 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Bean Managed Bean [class com.tien113.ui.MovieView] with qualifiers [@Any @Default] with viewName "MovieView" is one alternative
  10:17:27,105 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) com.tien113.ui.LoginView is annotated, the viewName is ""
  10:17:27,105 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Attempting to retrieve view with name "MovieView"
  10:17:27,105 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Looking for view with name "MovieView"
  10:17:27,105 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) com.tien113.ui.MovieView is annotated, the viewName is "MovieView"
  10:17:27,105 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Bean Managed Bean [class com.tien113.ui.MovieView] with qualifiers [@Any @Default] with viewName "MovieView" is one alternative
  10:17:27,105 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) com.tien113.ui.LoginView is annotated, the viewName is ""
  10:17:27,106 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Releasing creational context for current view org.jboss.weld.context.CreationalContextImpl@5182605a
  10:17:27,106 INFO  [com.vaadin.cdi.CDIViewProvider] (default task-9) Created new creational context for current view org.jboss.weld.context.CreationalContextImpl@5bfe6e21
  10:17:27,164 SEVERE [com.vaadin.server.DefaultErrorHandler] (default task-9) : java.lang.NullPointerException
      at com.tien113.ui.MovieView.genreFilterComboBox(MovieView.java:180) [classes:]
      at com.tien113.ui.MovieView.movieLayout(MovieView.java:80) [classes:]
      at com.tien113.ui.MovieView.&lt;init&gt;(MovieView.java:70) [classes:]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.8.0_20-ea]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [rt.jar:1.8.0_20-ea]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.8.0_20-ea]
      at java.lang.reflect.Constructor.newInstance(Constructor.java:408) [rt.jar:1.8.0_20-ea]
      at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:110) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:84) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:71) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:85) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:183) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:149) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at com.vaadin.cdi.internal.UIBeanStore.getBeanInstance(UIBeanStore.java:57) [vaadin-cdi-1.0.0.alpha2.jar:1.0.0.alpha2]
      at com.vaadin.cdi.internal.UIScopedContext.get(UIScopedContext.java:105) [vaadin-cdi-1.0.0.alpha2.jar:1.0.0.alpha2]
      at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:733) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:753) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.util.ForwardingBeanManager.getReference(ForwardingBeanManager.java:61) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at org.jboss.weld.bean.builtin.BeanManagerProxy.getReference(BeanManagerProxy.java:80) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
      at com.vaadin.cdi.CDIViewProvider.getView(CDIViewProvider.java:213) [vaadin-cdi-1.0.0.alpha2.jar:1.0.0.alpha2]
      at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:512) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.tien113.ui.LoginView.lambda$0(LoginView.java:80) [classes:]
      at com.tien113.ui.LoginView$$Lambda$2/843139639.buttonClick(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_20-ea]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_20-ea]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_20-ea]
      at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_20-ea]
      at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:978) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.ui.Button.fireClick(Button.java:393) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.ui.Button$1.click(Button.java:57) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_20-ea]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_20-ea]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_20-ea]
      at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_20-ea]
      at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:281) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:174) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:93) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:237) [vaadin-server-7.3.0.beta1.jar:7.3.0.beta1]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:123) [undertow-websockets-jsr-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_20-ea]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_20-ea]
      at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_20-ea]
  </code></pre>
  
  <p>It threw error on the line I use _service.</p>
  
  <p>Can anyone help me, please....</p>