Cannot inject ExternalContext or RequestParam in CDI @RequestScoped managed Bean

Viewed 1080

Searching around the web I found that it should be possible to @Inject some convenient JSF Objects into CDI beans, these objects should be Produced by JSF and exposed via Qualifiers in javax.faces.annotation.* (like @RequestMap or @SessionMap).

However, I am not being able to @Inject these resources into CDI Beans. Even injecting ExternalContext or FacesContext fails which, as stated in JSF 2.3-spec should be possible to @Inject as well as the following:

  • javax.faces.application.ResourceHandler
  • javax.faces.context.Flash

  • javax.servlet.http.HttpSession <-- this one is working

@RequestScoped
public class SimpleRequestParamReportProvider implements ReportParamsProvider {
    @Inject // <-- FAILS
    ExternalContext externalContext;

    @Inject // <-- FAILS
    FacesContext facesContext;

    @Inject @RequestMap // <-- FAILS
    Map<String, Object> requestMap;

    @Inject // <-- WORKS
    HttpSession httpSession;

Error shown at application startup:

Unsatisfied dependencies for type FacesContext with qualifiers @Default at injection point [BackedAnnotatedField] @Inject report.SimpleRequestParamReportProvider.facesContext

I am using JBoss EAP 7.2 which is JSF 2.3 compliant https://access.redhat.com/articles/113373

Has anyone else ran into this same issue? Is there something I am missing?

EDIT Here is the WEB-INF/faces-config-xml I am using

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
    version="2.3">
</faces-config>

EDIT 2: Injection of JSF objects is working once I add a @FacesConfig annotated java class:

@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class FacesActivator {}
0 Answers
Related