Primefaces ExceptionHandler在展示中不起作用

fai*_*alb 4 ajax jsf exception-handling primefaces jsf-2

我在primefaces中尝试了新的ExceptionHandler标记,但似乎我遗漏了这个标记的东西.

基本上我的代码与http://www.primefaces.org/showcase/ui/misc/exceptionHandler.xhtml中的相同,问题是添加此标记不会改变任何我在客户端没有得到任何东西的东西.标准的js API无法使用素数按钮:

jsf.ajax.addOnError(function(data) {alert('Error');})
Run Code Online (Sandbox Code Playgroud)

我在运行的应用程序和Primefaces展示之间注意到的唯一区别是我得到的ajax响应与showcase的不同:

我的回复:

在此输入图像描述

陈列柜的回应

在此输入图像描述

这是代码

<h:form>
<h3 style="margin-top:0">AJAX</h3>
<p:commandButton actionListener="#{exceptionHandlerView.throwViewExpiredException}"
                 ajax="true"
                 value="Throw ViewExpiredException!" />
<p:commandButton actionListener="#{exceptionHandlerView.throwNullPointerException}"
                 ajax="true"
                 value="Throw NullPointerException!" />
<p:commandButton actionListener="#{exceptionHandlerView.throwWrappedIllegalStateException}"
                 ajax="true"
                 value="Throw IllegalStateException!" />

<h3>Non-AJAX</h3>
<p:commandButton actionListener="#{exceptionHandlerView.throwViewExpiredException}"
                 ajax="false"
                 value="Throw ViewExpiredException!" />
<p:commandButton actionListener="#{exceptionHandlerView.throwNullPointerException}"
                 ajax="false"
                 value="Throw NullPointerException!" />


<p:ajaxExceptionHandler type="javax.faces.application.ViewExpiredException"
                        update="exceptionDialog"
                        onexception="PF('exceptionDialog').show();" />

<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>
Run Code Online (Sandbox Code Playgroud)

package org.primefaces.showcase.view.misc;


import javax.faces.FacesException;
import javax.faces.application.ViewExpiredException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@RequestScoped
public class ExceptionHandlerView {

    public void throwNullPointerException() {
        throw new NullPointerException("A NullPointerException!");
    }

    public void throwWrappedIllegalStateException() {
        Throwable t = new IllegalStateException("A wrapped IllegalStateException!");
        throw new FacesException(t);
    }

    public void throwViewExpiredException() {
        throw new ViewExpiredException("A ViewExpiredException!",
                FacesContext.getCurrentInstance().getViewRoot().getViewId());
    }
}
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 14

再次打开你给出的展示链接.现在单击" 文档"选项卡.你会看到其他人:

11.3异常处理程序

PrimeFaces提供了一个内置的异常处理程序,可以轻松处理ajax和非ajax请求中的异常.

组态

Face配置文件中需要ExceptionHandler和ElResolver.

<application>
     <el-resolver>
         org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
    </el-resolver>
</application>
<factory>
    <exception-handler-factory>
       org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
    </exception-handler-factory>
</factory>
Run Code Online (Sandbox Code Playgroud)

按指示行动.