When I upgraed my Java EE 7 sample to the newest Java EE 8, the first thing confused me is the CDI beans are not recognized in Facelects template in a JSF 2.3 based web applicaiton, which is working in the development version, but in the final release version, they are always resolved as null. I filed an issue on Mojarra and discussed it with the developers from communities and the JSF experts.
According to the content of README, In a JSF 2.3 application, to activate CDI support, declaring a 2.3 versioned faces-config.xml and adding javax.faces.ENABLE_CDI_RESOLVER_CHAIN in web.xml is not enough, you have to declare @FacesConfig annotated class to enable CDI.
Here is the steps I created a workable JSF 2.3 application in Java EE 8.
Create a Java web application, this can be done easily by NetBeans IDE, or generated by Maven archetype, for example.
JSF 2.3 provides some options to activate the new features added in 2.3.
ENABLE_VALIDATE_WHOLE_BEAN is used to enable class level Bean validation
ENABLE_WEBSOCKET_ENDPOINT is used to enable web socket support
ENABLE_CDI_RESOLVER_CHAIN is originally designed for enabling CDI, but it seems it is replaced by @FacesConfig
DISABLE_FACESSERVLET_TO_XHTML will disable JSF servlet mapping to *.xhtml. By default, JSF Servlet will serve \.xhtml*.
Declare a @FacesConfig annotated class to activate CDI in JSF 2.3.
@FacesConfig(// Activates CDI build-in beans version =JSF_2_3 )publicclassConfigurationBean { }
Open the source code of FacesConfig, you will know it is a standard CDI Qualifier.
@Qualifier @Target(TYPE) @Retention(RUNTIME)public @interfaceFacesConfig {publicstaticenumVersion { /** * <p class="changed_added_2_3">This value indicates CDI should be used * for EL resolution as well as enabling JSF CDI injection, as specified * in Section 5.6.3 "CDI for EL Resolution" and Section 5.9 "CDI Integration".</p> */ JSF_2_3 }/** * <p class="changed_added_2_3">The value of this attribute indicates that * features corresponding to this version must be enabled for this application.</p> * @return the spec version for which the features must be enabled. */ @NonbindingVersionversion()defaultVersion.JSF_2_3; }