我在WildFly 8.2上运行Java EE 7应用程序。我使用OmniFaces 1.8.1。
我在与NullPointerExceptions相关的日志文件FacesViewsForwardingFilter中看到:

2015-02-11 15:42:22,870 ERROR [io.undertow.request] (default task-12) UT005023: Exception handling request to /login: java.lang.NullPointerException
        at org.omnifaces.facesviews.FacesViewsForwardingFilter.doFilter(FacesViewsForwardingFilter.java:122) [omnifaces-1.8.1.jar:1.8.1-20140603]
        at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:77) [omnifaces-1.8.1.jar:1.8.1-20140603]
        at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
        at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]




2015-02-11 15:42:31,524 ERROR [io.undertow.request] (default task-15) UT005023: Exception handling request to /search.xhtml: java.lang.NullPointerException
        at org.omnifaces.facesviews.FacesViewsForwardingFilter.doFilter(FacesViewsForwardingFilter.java:153) [omnifaces-1.8.1.jar:1.8.1-20140603]
        at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:77) [omnifaces-1.8.1.jar:1.8.1-20140603]
        at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]


在服务器启动期间,我看到以下信息:

2015-02-11 12:28:35,667 ERROR [io.undertow.request] (default task-3) UT005023: Exception handling request to /terms/index: java.lang.IllegalStateException: Illegal attempt to set ViewHandler after a response has been rendered.
        at com.sun.faces.application.ApplicationImpl.setViewHandler(ApplicationImpl.java:583) [jsf-impl-2.2.8-jbossorg-1.jar:]
        at javax.faces.application.ApplicationWrapper.setViewHandler(ApplicationWrapper.java:288) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
        at org.jboss.as.jsf.injection.weld.ForwardingApplication.setViewHandler(ForwardingApplication.java:367) [wildfly-jsf-injection-8.2.0.Final.jar:8.2.0.Final]
        at org.omnifaces.facesviews.FacesViewsForwardingFilter.init(FacesViewsForwardingFilter.java:95) [omnifaces-1.8.1.jar:1.8.1-20140603]
        at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:111) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
        at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:85)


web.xml中的相关配置为:

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.html</url-pattern>
    <url-pattern>*.xhtml</url-pattern>
    <url-pattern>/javax.faces.resource/*</url-pattern>
</servlet-mapping>
<context-param>
    <param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
    <param-value>/*.xhtml</param-value>
</context-param>


这是怎么引起的,我该如何解决?

最佳答案

这些NPE表明过滤器的初始化失败。在服务器启动期间,您应该能够在日志中更早地找到线索。


2015-02-11 12:28:35,667错误[io.undertow.request](默认任务3)UT005023:对/ terms / index的异常处理请求:java.lang.IllegalStateException:响应尝试后非法尝试设置ViewHandler被渲染。


IllegalStateException是有用的提示。 FacesViewsViewHandler在OmniFaces 1.x中通过FacesViewsForwardingFilter在与/*.xhtml匹配的URL上第一次请求时被延迟初始化。但是,如果在过滤器之前调用FacesServlet,则由于该异常而失败。您有一个可疑的*.html映射,该映射将触发FacesServlet而不触发过滤器。您是否有一个纯HTML页面作为欢迎文件?为什么不将其重命名为*.xhtml

无论如何,该初始化排序错误是OmniFaces 2.0中的fixed。因此,升级应该可以。

09-25 21:25