1

在 WildFly 8-1 上,我有primefaces-5.1.jar并且primefaces-extensions-2.1.0.jar在我的 webappsWEB-INF/lib目录中。

我已经配置WEB-INF/faces-config.xml

<?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 http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
  <application>
    <el-resolver>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver</el-resolver>
  </application>

  <factory>
    <exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
  </factory>
</faces-config>

我有以下JSF。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:p="http://primefaces.org/ui"
  xmlns:pe="http://primefaces.org/ui/extensions">
<h:head></h:head>
<h:body>
  <h:form id="form">
    <pe:ajaxErrorHandler body="ERROR"/>
    <p:commandButton actionListener="#{dossierResumen.excepcion}" value="Excepción"/>
  </h:form>
</h:body>
</html>

DossierResumen#excepcion()在哪里

public void excepcion() {
  throw new NullPointerException("EXCEPCION! EXCEPCION!");
}

当我单击按钮时,根本没有弹出窗口;页面被重定向到 URL 中定义的错误 500 web.xml。在日志中,我得到以下堆栈跟踪墙:

我究竟做错了什么?

15:44:14,206 错误 [stderr](默认任务 42)java.lang.NullPointerException:异常!例外!15:44:14,206 错误 [stderr](默认任务 42)在 es.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen.excepcion(DossierResumen.java:55)15:44:14,206 错误 [stderr](默认任务 42)在 es.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen$Proxy$_$$PrimeExceptionHandler](默认任务 42)例外!异常!:java.lang.NullPointerException:异常!例外!在 es.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen.excepcion(DossierResumen.java:55) [classes:] 在 es.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen$Proxy$$$_WeldClientProxy.excepcion(Unknown Source) [classes:] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_55] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [ rt.jar:1.7.0_55] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_55] 在 java.lang.reflect.Method.invoke(Method.java:606) [ rt.jar:1.7.0_55] 在 com.sun.el.parser.AstValue.invoke(AstValue.java:275) [javax.el-3.0.0.jar:] 在 com.sun.el.MethodExpressionImpl.invoke( MethodExpressionImpl.java:304) [javax.el-3.0.0.jar:] at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) [weld-core-impl-2.1.2. Final.jar:2014-01-09 09:23] 在 org.jboss.weld.el.WeldMethodExpression。调用(WeldMethodExpression.java:50)[weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] 在 org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java :40) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core -impl-2.1.2.Final.jar:2014-01-09 09:23] 在 javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149) [jboss-jsf-api_2.2_spec-2.2.6。 jar:2.2.6] 在 javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6] 在 javax.faces.component.UIComponentBase .broadcast(UIComponentBase.java:813) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6] 在 javax.faces.component.UICommand.broadcast(UICommand.java:300) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6] 在 javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) [jboss-jsf-api_2.2_spec-2.2.6 .jar:2.2.6] 在 javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6] 在 com.sun.faces。 lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.2.6-jbossorg-4.jar:] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf- impl-2.2.6-jbossorg-4.jar:] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [jsf-impl-2.2.6-jbossorg-4.jar:] at javax .faces.webapp.FacesServlet.service(FacesServlet.java:646) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6] 在 io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java :85) [undertow-servlet-1.0.15.Final。jar:1.0.15.Final] 在 io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 io .undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest (SecurityContextAssociationHandler.java:78) 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow。 servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.servlet.handlers。security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar :1.0.15.Final] 在 io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 io。 undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow。servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler. java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15 .Final.jar:1.0.15.Final] 在 org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java :25) [undertow-core-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15。最终的.jar:1.0.15。最终] 在 io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.servlet.handlers.ServletInitialHandler .dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow -servlet-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar: 1.0.15.Final] 在 io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final] 在 io.undertow.server.HttpServerExchange $1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_55] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615) [rt.jar:1.7.0_55] 在 java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_55]

更新:

应 Guaido79 的要求,我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>seleneWar</display-name>
  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>

  <error-page>
    <error-code>500</error-code>
    <location>/error/500.xhtml</location>
  </error-page>

  <context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
  </context-param>

  <context-param>
    <param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>
    <param-value>true</param-value>
  </context-param>

  <resource-ref>
    <res-ref-name>jsf/ProjectStage</res-ref-name>
    <res-type>java.lang.String</res-type>
  </resource-ref>

</web-app>
4

2 回答 2

5

该组件中有两种模式:简单模式和扩展模式。

在简单模式下,您不需要在faces-config.xml. 所以你可以删除这些行:

<application>
    <el-resolver>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver</el-resolver>
</application>

<factory>
    <exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
</factory>

或者删除整个faces-config.xml文件,因为它是你唯一拥有的东西。然后您可以测试简单模式,该模式工作正常,无需在 web.xml 中定义任何其他内容。这可能足以满足您的需求

从错误跟踪来看,似乎在扩展模式下(使用该faces-config.xml配置),组件需要在您的web.xml. 您不希望重定向到错误页面,因此如果您将以下代码添加到您web.xml的示例作品中,但不满足您的需要:

<error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>/error/500.xhtml</location>
</error-page>

无论如何,强烈建议使用本p:ajaxExceptionHandler机组件,因为看起来 PrimeFaces Extensions 的作者将来可能会删除该组件,因为它不再需要(链接)已经在版本 3.2.0 中删除了该组件。(关联)

于 2014-10-28T12:54:02.427 回答
1

它是如何配置你的 web.xml 的?对我来说,它正在使用这种配置:

示例 web.xml:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/pages/errorpages/sessione-scaduta.xhtml</location>
</error-page>
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/pages/errorpages/runtime-error.xhtml</location>
</error-page>

面孔-config.xml

<application>
        <message-bundle>ValidationMessages</message-bundle>
        <resource-bundle>
            <base-name>/Bundle</base-name>
            <var>bundle</var>
        </resource-bundle>
        <el-resolver>
            org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
        </el-resolver>
        <locale-config>
            <default-locale>it</default-locale>
        </locale-config>
        <view-handler>it.infogroup.wrl.web.utils.PathTrimViewHandler</view-handler>
    </application>

    <factory>
        <exception-handler-factory>
            org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
        </exception-handler-factory>
    </factory>

使用此配置,您将在错误时被重定向。

如果您需要弹出窗口,您需要像这样更改代码(来自 primefaces 展示):

<p:ajaxExceptionHandler type="java.lang.NullPointerException"
                            update="exceptionDialog"
                            onexception="PF('exceptionDialog').show();" />

    <p:dialog id="exceptionDialog" header="Exception '#{pfExceptionHandler.type}' occured!" widgetVar="exceptionDialog"
              height="500px">
        Message: #{pfExceptionHandler.message} <br/>
        StackTrace: <h:outputText value="#{pfExceptionHandler.formattedStackTrace}" escape="false" /> <br />

        <p:button onclick="document.location.href = document.location.href;"
                  value="Reload!"
                  rendered="#{pfExceptionHandler.type == 'javax.faces.application.ViewExpiredException'}" />
    </p:dialog>
于 2014-10-27T11:56:15.740 回答