5

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 {}
jfer
  • 81
  • 6
  • This exception will be thrown when you're not actually using JSF 2.3+ (i.e. when you think that you're using JSF 2.3, but the environment/build actually isn't correctly configured as-is). The cause of this problem is however not visible in the information provided so far. So this question cannot be answered. One of probable causes is that you didn't install/activate JSF 2.3 in JBoss EAP 7.2. Another probable cause is that you forgot to set the JSF 2.3 flag in faces-config.xml and/or the `@FacesConfig` trigger. – BalusC Jun 06 '19 at 17:21
  • Hi @BalusC. Thanks for answering! I updated my question with the faces-config.xml my application is using. Is there a flag I am missing in there to activate jsf 2.3? – jfer Jun 06 '19 at 19:53
  • @BalusC your comment pointed me to the right direction. I was not aware of the need for a ```@FacesConfig``` activator, which seems to have resolved the Injection problem. Is there a way to activate from faces-config.xml sparing the need for ```@FacesConfig```? Thanks. – jfer Jun 06 '19 at 20:43
  • Just to mention another way in case it helps someone, I was able to get `ExternalContext` by using `FacesContext`: `FacesContext.getCurrentInstance().getExternalContext()` – SebaGra Jun 10 '20 at 12:44

0 Answers0