0

i setup a working CDI for JSF. In the login i can use #{AuthCtrl.logIn()}, #{AuthCtrl.userName}, #{AuthCtrl.pwd} ... without problems, but the CDI fails in @webfilter, where authCtrl is always null

@WebFilter("/*")
public class AuthFilter implements Filter {
    @Inject
    private AuthCtrl authCtrl;
    ...



@Named(value = "AuthCtrl")
@javax.enterprise.context.SessionScoped
public class AuthCtrl implements Serializable {
... 

Any ideas why? thanks!

btw. i use openwebbeans 1.2.6, tomcat 7, myfaces 2.2.5, myfaces.codi 1.0.6

5
  • cdi does not fail on your @webfilter. The only reason this can happen is that either DI is not performed (because CDI dos not know about your webfilter), or your AuthCtrl producer (if you have one) returns null. Oct 16, 2014 at 8:44
  • Also this might save you a lot of time, when you succeed in fixing your problem: stackoverflow.com/questions/9609656/… Oct 16, 2014 at 8:48
  • filter is in the same project as my JSF stuff so i think CDI should know about it and i don't have a producer for AuthCtrl
    – george
    Oct 16, 2014 at 20:00
  • CDI 1.0 and Servlet 3.1 do not support injection into filters.
    – John Ament
    Oct 18, 2014 at 13:37
  • If you configured to use OWB via WebBeansConfigurationListener than there is no support for injection into other EE components like Servlets, EJBs, etc. The benefit of this setup is the very small footprint and very high performance. You should be able to use CODIs BeanManagerProvider to get access to your CDI beans (lazily at the first request) though: authCtrl = BeanManagerProvider.getInstance().getContextualReference(AuthCtrl.class); If you need a more in depth EE integration than try Apache TomEE-1.7.1 which includes both OpenWebBeans and MyFaces in exactly the versions you use.
    – struberg
    Oct 22, 2014 at 15:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.