升级到Mojarra 2.2.8-07或更高版本时未找到托管bean

时间:2015-09-02 08:12:36

标签: jsf spring-boot managed-bean mojarra

我使用Spring Boot,JSF,PrimeFaces。

目前,我无法将我的应用程序更新为新的JSF 2.2.12。

一切正常,例如使用JSF 2.2.8-06和PrimeFaces 5.2,但从JSF 2.2.8-07开始,直到2.2.12版本,我无法从XHTML页面访问我的ManagedBean。

从JSF 2.2.8-07 +版本改变了什么以及如何修复它?

我的豆子:

// Edit slider
$("#editSlider").editRangeSlider("values", 20, 100);

的index.xhtml:

@ManagedBean
@ViewScoped
public class HelloBean implements Serializable {

    private static final long serialVersionUID = 8569928214435846079L;

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

}

WebInitializer:

<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>

使用@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()); } } 一切正常,除了在控制台中出现以下错误:

JSF 2.2.8-06

已更新

我得到了它的工作:

我添加了资源/ META-INF / faces-config.xml文件:

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

并且还更改了我的HelloBean中的注释,而不是它看起来像:

<?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>

这是一个正确的方法吗?使用@Named @ViewScoped public class HelloBean implements Serializable { private static final long serialVersionUID = 8569928214435846079L; public String getHello() { return "Hello from PrimeFaces and Spring Boot!"; } } 代替@Named是不是一个好主意?

0 个答案:

没有答案