I am trying to migrate my JSF + PrimeFaces (UI) + Spring application from Java 8 to Java 17, whilst also migrating Spring version to 6. For this to work, there is a need to move from the javax libraries to jakarta libraries. jsf-api and jsf-impl of com.sun.faces are removed. Keeping only org.glassfish:jakarta.faces. Did add required libraries from different sources available on the internet.
The problem where I am stuck is that FacesContext facesContext = FacesContext.getCurrentInstance(); was used in a @PostConstruct annotated method of a bean that is @ViewScoped and is used with @Named annotation.
I am getting the exception since facesContext is null, the object of facesContext is not getting initialised.
FacesConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_0.xsd"
version="4.0">
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
</locale-config>
<resource-bundle>
<base-name>messages</base-name>
<var>msg</var>
</resource-bundle>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="6.0"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
<display-name>controlfwk</display-name>
<description>controlfwk</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:spring-context.xml
</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.default</param-name>
<!--<param-value>${spring.profile}</param-value>-->
<param-value>prod</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>
com.abc.def.cfk.web.service.rest.RestService
</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true </param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>smoothness</param-value>
</context-param>
<session-config>
<session-timeout>360</session-timeout>
<cookie-config>
<path>/</path>
</cookie-config>
</session-config>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>home.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>
I tried removing FacesContext as in commented, UI does come up with that but that's not a solution.
I added all Jakarta EE jars that were suggested in different forums but could not make any difference. Replaced ManagedBean with Named and ManagedProperty with Inject annotations.
I am expecting to get FacesContext object for something like:
FacesContext facesContext = FacesContext.getCurrentInstance();
Map<String, String> parameterMap = facesContext.getExternalContext().getRequestParameterMap();
This is just one example of I need FacesContext.
Note: Things did work with Java 8, PrimeFaces 6, JSF 2.2.8-02, Spring 4.x.
Edit: As per the comment given by BalusC, I have removed jakarta.faces-api and added org.glassfish:jakarta.faces.
I am still not getting the FacesContext object. I followed everything mentioned in the duplicate link How to properly install and configure JSF libraries via Maven? provided.