I'm trying to get Spring Boot to work with JSF. The FacesServlet is initialized and the website correctly rendered with Primefaces. But at the point where I call a JSF- or Spring-Bean, nothing is shown.
I know that this question was multiple times asked, but none of them solved my problem. After hours of searching, i don't get it to work. Am I missing something?
Setup:
- Spring Boot 1.2.7
- Primefaces 5.2
- JSF 2.2
What I tried:
- Integrate Jsf Spring Boot Tutorial
- Spring Boot and JSF/Primefaces/Richfaces
- Spring Boot with JSF; Could not find backup for factory javax.faces.context.FacesContextFactory
What I have
Application.java
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public FacesServlet facesServlet() {
return new FacesServlet();
}
@Bean
public ServletRegistrationBean facesServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(facesServlet(), new String[] { "*.xhtml" });
registration.setName("FacesServlet");
registration.setLoadOnStartup(1);
return registration;
}
@Configuration
static class ConfigureJSFContextParameters implements ServletContextInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", "true");
servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
servletContext.setInitParameter("encoding", "UTF-8");
}
}
@Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
}
}
JsfBean.java
@ManagedBean
public class JsfBean {
private String welcomeMessage = "Populated by JSF created bean";
public String getWelcomeMessage() {
return welcomeMessage;
}
}
SpringBean.java
@Component
public class SpringBean {
private String welcomeMessage = "Populated by spring created bean";
public String getWelcomeMessage() {
return welcomeMessage;
}
}
index.xhtml
<!DOCTYPE html>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui" encoding="UTF-8">
<html>
<h:head>
</h:head>
<h:body>
<h1>Rechnung</h1>
<h3>#{springBean.welcomeMessage}</h3>
<h3>#{jsfBean.welcomeMessage}</h3>
</h:body>
</html>
</f:view>
Output
<h1>Rechnung</h1>
<h3></h3>
<h3></h3>