prifaces扩展ajaxErrorHandler不工作



在WildFly 8-1我有primefaces-5.1.jarprimefaces-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!");
}

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

我做错了什么?

15:44:14 . 206 ERROR [stderr] (default task-42)java.lang.NullPointerException: EXCEPCION !EXCEPCION !15:44:14,206错误[stderr](默认任务-42)es.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen.excepcion (DossierResumen.java: 55)15:44:14 . 206 ERROR [stderr] (default task-42) ates.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen代理美元$ _ $ $WeldClientProxy.excepcion(未知[来源]15:44:14 . 206 ERROR [stderr](默认任务-42)atsun.reflect.NativeMethodAccessorImpl。invoke0(本地方法)15:44:14 . 206 ERROR [stderr] (default task-42) atsun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java: 57)15:44:14 . 207 ERROR [stderr] (default task-42) atsun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java: 43)15:44:14 . 207 ERROR [stderr] (default task-42) atjava.lang.reflect.Method.invoke(Method.java:606) 15:44:14 . 207错误[stderr](默认任务-42)atcom.sun.el.parser.AstValue.invoke 15:44:14,207 (AstValue.java: 275)错误[stderr](默认任务-42)com.sun.el.MethodExpressionImpl.invoke (MethodExpressionImpl.java: 304)15:44:14 . 207 ERROR [stderr] (default task-42) atorg.jboss.weld.util.el.ForwardingMethodExpression.invoke (ForwardingMethodExpression.java: 40)15:44:14 . 207 ERROR [stderr] (default task-42) atorg.jboss.weld.el.WeldMethodExpression.invoke (WeldMethodExpression.java: 50)15:44:14 . 208 ERROR [stderr] (default task-42) atorg.jboss.weld.util.el.ForwardingMethodExpression.invoke (ForwardingMethodExpression.java: 40)15:44:14 . 208 ERROR [stderr] (default task-42) atorg.jboss.weld.el.WeldMethodExpression.invoke (WeldMethodExpression.java: 50)15:44:14 . 208 ERROR [stderr] (default task-42) atjavax.faces.event.MethodExpressionActionListener.processAction (MethodExpressionActionListener.java: 149)15:44:14 . 208 ERROR [stderr] (default task-42) atjavax.faces.event.ActionEvent.processListener (ActionEvent.java: 88)15:44:14 . 208 ERROR [stderr] (default task-42) atjavax.faces.component.UIComponentBase.broadcast (UIComponentBase.java: 813)15:44:14 . 208 ERROR [stderr] (default task-42) atjavax.faces.component.UICommand.broadcast (UICommand.java: 300)15:44:14 . 209 ERROR [stderr] (default task-42) atjavax.faces.component.UIViewRoot.broadcastEvents (UIViewRoot.java: 790)15:44:14 . 209 ERROR [stderr] (default task-42) atjavax.faces.component.UIViewRoot.processApplication (UIViewRoot.java: 1282)15:44:14 . 209 ERROR [stderr] (default task-42) atcom.sun.faces.lifecycle.InvokeApplicationPhase.execute (InvokeApplicationPhase.java: 81)15:44:14 . 209 ERROR [stderr] (default task-42) atcom.sun.faces.lifecycle.Phase.doPhase 15:44:14,209 (Phase.java: 101)错误[stderr](默认任务-42)com.sun.faces.lifecycle.LifecycleImpl.execute (LifecycleImpl.java: 198)15:44:14 . 209 ERROR [stderr] (default task-42) atjavax.faces.webapp.FacesServlet.service (FacesServlet.java: 646)15:44:14 . 210 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.ServletHandler.handleRequest (ServletHandler.java: 85)15:44:14 . 210 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest (ServletSecurityRoleHandler.java: 61)15:44:14 . 210 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest (ServletDispatchingHandler.java: 36)15:44:14 . 210 ERROR [stderr] (default task-42) atorg.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest (SecurityContextAssociationHandler.java: 78)15:44:14 . 210 ERROR [stderr] (default task-42) atio.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)15:44:14 . 210 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest (SSLInformationAssociationHandler.java: 113)15:44:14 . 211 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest (ServletAuthenticationCallHandler.java: 56)15:44:14 . 211 ERROR [stderr] (default task-42) atio.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)15:44:14 . 211 ERROR [stderr] (default task-42) atio.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest (AbstractConfidentialityHandler.java: 45)15:44:14 . 211 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest (ServletConfidentialityConstraintHandler.java: 61)15:44:14 . 211 ERROR [stderr] (default task-42) atio.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest (AuthenticationMechanismsHandler.java: 58)15:44:14 . 212 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest (CachedAuthenticatedSessionHandler.java: 70)15:44:14 . 212 ERROR [stderr] (default task-42) atio.undertow.security.handlers.SecurityInitialHandler.handleRequest (SecurityInitialHandler.java: 76)15:44:14 . 212 ERROR [stderr] (default task-42) atio.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)15:44:14 . 212 ERROR [stderr] (default task-42) atorg.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest (JACCContextIdHandler.java: 61)15:44:14 . 212 ERROR [stderr] (default task-42) atio.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)15:44:14 . 212 ERROR [stderr] (default task-42) atio.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)15:44:14 . 213 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest (ServletInitialHandler.java: 240)15:44:14 . 213 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest (ServletInitialHandler.java: 227)15:44:14 . 213 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.ServletInitialHandler.access 000美元(ServletInitialHandler.java: 73)15:44:14 . 213 ERROR [stderr] (default task-42) atio.undertow.servlet.handlers.ServletInitialHandler 1.美元handlerequest (ServletInitialHandler.java: 146)15:44:14 . 213 ERROR [stderr] (default task-42) atio.undertow.server.Connectors.executeRootHandler (Connectors.java: 177)15:44:14 . 213 ERROR [stderr] (default task-42) atio.undertow.server.HttpServerExchange 1.美元运行(HttpServerExchange.java: 727)15:44:14 . 214 ERROR [stderr] (default task-42) atjava.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java: 1145)15:44:14 . 214 ERROR [stderr] (default task-42) atjava.util.concurrent.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 615)15:44:14 . 214 ERROR [stderr] (default task-42) atjava.lang.Thread.run(Thread.java:745) 15:44:14 . 214严重(org.primefaces.application.exceptionhandler.PrimeExceptionHandler)(default task-42)异常!EXCEPCION !:java.lang.NullPointerException: EXCEPCION !EXCEPCION !在es.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen.excepcion (DossierResumen.java: 55)(类:)es.imasmallorca.selene.webone.jsf.controller.dossier.DossierResumen代理$ $美元_WeldClientProxy.excepcion(未知来源)[类:]atsun.reflect.NativeMethodAccessorImpl。invoke0(本地方法)[rt.jar: 1.7.0_55]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] at 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:]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.invoke (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]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)2.2.6 [jboss-jsf-api_2.2_spec-2.2.6.jar:。]javax.faces.event.ActionEvent.processListener (ActionEvent.java: 88)2.2.6 [jboss-jsf-api_2.2_spec-2.2.6.jar:。]javax.faces.component.UIComponentBase.broadcast (UIComponentBase.java: 813)2.2.6 [jboss-jsf-api_2.2_spec-2.2.6.jar:。]javax.faces.component.UICommand.broadcast (UICommand.java: 300)2.2.6 [jboss-jsf-api_2.2_spec-2.2.6.jar:。]javax.faces.component.UIViewRoot.broadcastEvents (UIViewRoot.java: 790)2.2.6 [jboss-jsf-api_2.2_spec-2.2.6.jar:。]javax.faces.component.UIViewRoot.processApplication (UIViewRoot.java: 1282)2.2.6 [jboss-jsf-api_2.2_spec-2.2.6.jar:。]com.sun.faces.lifecycle.InvokeApplicationPhase.execute (InvokeApplicationPhase.java: 81)2.2.6 [jsf - impl。——jbossorg——4. - jar:]com.sun.faces.lifecycle.Phase.doPhase (Phase.java: 101)2.2.6 [jsf - impl。——jbossorg——4. - jar:]com.sun.faces.lifecycle.LifecycleImpl.execute (LifecycleImpl.java: 198)2.2.6 [jsf - impl。——jbossorg——4. - jar:]javax.faces.webapp.FacesServlet.service (FacesServlet.java: 646)2.2.6 [jboss-jsf-api_2.2_spec-2.2.6.jar:。]io.undertow.servlet.handlers.ServletHandler.handleRequest (ServletHandler.java: 85)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest (ServletSecurityRoleHandler.java: 61)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest (ServletDispatchingHandler.java: 36)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)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。最终)io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest (SSLInformationAssociationHandler.java: 113)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest (ServletAuthenticationCallHandler.java: 56)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest (AbstractConfidentialityHandler.java: 45)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest (ServletConfidentialityConstraintHandler.java: 61)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest (AuthenticationMechanismsHandler.java: 58)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest (CachedAuthenticatedSessionHandler.java: 70)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.security.handlers.SecurityInitialHandler.handleRequest (SecurityInitialHandler.java: 76)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)io.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)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。最终)io.undertow.server.handlers.PredicateHandler.handleRequest (PredicateHandler.java: 25)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest (ServletInitialHandler.java: 240)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest (ServletInitialHandler.java: 227)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.ServletInitialHandler.access 000美元(ServletInitialHandler.java: 73)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.servlet.handlers.ServletInitialHandler 1.美元handlerequest (ServletInitialHandler.java: 146)【undertow-servlet-1.0.15.Final.jar: 1.0.15。最终)io.undertow.server.Connectors.executeRootHandler (Connectors.java: 177)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)io.undertow.server.HttpServerExchange 1.美元运行(HttpServerExchange.java: 727)【undertow-core-1.0.15.Final.jar: 1.0.15。最终)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] at 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>

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

在简单模式下,您不需要在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版本中删除了该组件。(链接)

如何配置您的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>

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

相关内容

  • 没有找到相关文章

最新更新