0

I use Spring Boot, JSF, PrimeFaces.

Right now, I can't update my application to new JSF 2.2.12.

Everything works properly for example with JSF 2.2.8-06 and PrimeFaces 5.2 but starting from JSF 2.2.8-07 and up to 2.2.12 version I can't reach my ManagedBean from XHTML page.

What was changed from JSF 2.2.8-07+ version and how to fix it ?

My bean:

@ManagedBean
@ViewScoped
public class HelloBean implements Serializable {

    private static final long serialVersionUID = 8569928214435846079L;

    public String getHello() {
        return "Hello from PrimeFaces and Spring Boot!";
    }

}

index.xhtml:

<f:view xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:ng="http://xmlns.jcp.org/jsf/passthrough"
    xmlns:prime="http://primefaces.org/ui">
    <h:head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>Title</title>
        <style>
        body {font-size:12px; }
</style>
    </h:head>
    <h:body>
        <h:form>
            <prime:panel header="What do you see here?" >
                <div style="height:50px">
                    This is a simple PrimeFaces 5 project running on Spring Boot 1.1.4.
                </div>
            </prime:panel>
            <prime:panel header="JSF 2.2 Bean Access">
                #{helloBean.hello}
            </prime:panel>
        </h:form>
    </h:body>
</f:view>

WebInitializer:

@Configuration
public class WebInitializer extends SpringBootServletInitializer implements ServletContextAware {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    @Bean
    public DispatcherServlet dispatcherServlet() {
        DispatcherServlet dispatcherServlet = new DispatcherServlet();
        dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
        return dispatcherServlet;
    }

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        FacesServlet servlet = new FacesServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet, "*.xhtml");
        servletRegistrationBean.setLoadOnStartup(1);
        return servletRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
        return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
    }
}

With JSF 2.2.8-06 everything works properly except following errors in the console:

2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 18 at position 32
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 33
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 34
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 35
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 30 at position 36
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 15 at position 98
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 101
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 97 at position 102
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 15 at position 104

UPDATED

I got it working:

I have added resources/META-INF/faces-config.xml file:

<?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/web-facesconfig_2_2.xsd"
    version="2.2">
    <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>

    <lifecycle>
        <phase-listener>org.springframework.web.jsf.DelegatingPhaseListenerMulticaster</phase-listener>
    </lifecycle>
</faces-config>

and also changed annotations in my HelloBean, not it looks like:

@Named
@ViewScoped
public class HelloBean implements Serializable {

    private static final long serialVersionUID = 8569928214435846079L;

    public String getHello() {
        return "Hello from PrimeFaces and Spring Boot!";
    }

}

Is it a proper way to go ? Is it a good idea to use @Named instead of @ManagedBean ?

alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • I have added the code – alexanoid Sep 02 '15 at 09:00
  • does it run in something like Wildfly? (to make sure it is or is not related to spring-boot) – Kukeltje Sep 02 '15 at 09:06
  • no, it works in Spring Boot embedded Tomcat. With JSF 2.2.8-06 everything works properly – alexanoid Sep 02 '15 at 09:14
  • I meant what IF you run this simple example in wildfly or plain tomcat... with newer jsf versions... – Kukeltje Sep 02 '15 at 09:44
  • I have updated my question with a solution, could you please verify it ? – alexanoid Sep 02 '15 at 10:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88572/discussion-between-alexanoid-and-kukeltje). – alexanoid Sep 02 '15 at 11:29
  • No I can't verify since I do not use spring-boot or any spring stuff whatsoever and use mojarra 2.2.10 without any problems. I can only help you to get your question s.m.a.r.t. – Kukeltje Sep 02 '15 at 11:51
  • Are you using Mojarra as the JSF implementation? I've got Mojarra 2.2.8 running in Spring boot with no problem. The only problem I had was with PF `fileUpload` component, and I did solve it: http://stackoverflow.com/questions/27552227/primefaces-fileupload-not-working-in-spring-boot – Aritz Sep 03 '15 at 06:21
  • It works up to Mojarra 2.2.8-06, starting Mojarra 2.2.8-07+ it doesn't work with ManagedBean annotation. – alexanoid Sep 03 '15 at 06:50

0 Answers0