FacesContext not injectable in Wildfly 14 with JSF 2.3 (Mojarra, main module)

 ̄綄美尐妖づ 提交于 2019-12-01 00:37:47

According to

https://github.com/javaserverfaces/mojarra#activating-cdi-in-jsf-23

this is the answer:

By default, JSF 2.3 will run in JSF 2.2 modus as to CDI support. Even when you use a JSF 2.3 compatible faces-config.xml. In other words, the new JSF 2.3 feature of injection and EL resolving of JSF artifacts (spec issue 1316) won't work until you explicitly activate this. In other words, @Inject FacesContext doesn't work by default. This is necessary in order for JSF 2.3 to be fully backwards compatible.

There is currently only one way to activate CDI in JSF 2.3 and herewith make JSF 2.3 to run in full JSF 2.3 modus. Put the @FacesConfig annotation on an arbitrary CDI managed bean. For example, a general startup/configuration bean.

@FacesConfig
@ApplicationScoped
public class YourApplicationConfig {
    // ...
}

Full example:

import javax.enterprise.context.ApplicationScoped;
import javax.faces.annotation.FacesConfig;

@FacesConfig
@ApplicationScoped
public class Jsf23Activator {
    // ...
}

You need the @ApplicationScoped annotation or it will not work. After that in my startup the console finally displays:

14:23:28,805 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 82) Initializing Mojarra 2.3.5.SP2 for context '/blah'
14:23:30,415 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 82) Monitoring file:/C:/dev/servers/wildfly-14.0.1.Final/standalone/deployments/blah.war/WEB-INF/faces-config.xml for modifications
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!