Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1179

@Inject doesn't work in base class if a derived class is annotated with @ViewScope

XMLWordPrintable

      Currently I have headache with MyFaces CODI mapping / porting of JSF @ViewScope to CDI (https://svn.apache.org/repos/asf/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/scope/view/). This is quite good with OpenWebBeans, but not with Weld. @Inject in a base class doesn't work in JBoss 7 if the derived class has JSF @ViewScope. It works if it has CODI's @ViewAccessScope. But not with @ViewScope. Example:

      public abstract class A implement Serializable {
          @Inject private SomeSessionScopedBean bean;
      
          public SomeSessionScopedBean getBean() {
              return bean;
          }  
      }
      
      @Named
      @ViewScope
      public class B extends A {
          public void doSomething() {
              getBean().someMethod();   // NullPointerException here because bean was not injected
          } 
      }
      

      It works with OWB as I said. And it works in Weld too if I move @Inject ... to the class B. I think this is because Weld doesn't know about mapping of ViewScope.class, there isn't a SPI Extension in META-INF/services (no new annotation). Right? Can you confirm this?

      Many thanks in advance for any tips.

              marko.luksa@gmail.com Marko Luksa (Inactive)
              ova_jira Oleg Varaksin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: