JSF中未捕获异常处理

JSF中未捕获异常处理

本文介绍了JSF中未捕获异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个过滤器来处理异常(请参阅)

I am trying to create a filter to handle exceptions (see Handling Uncaught Exception in JSF)

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
      try {
          log.info("check filter is running");
            chain.doFilter(request, response);
        } catch (Exception e) {
            log.error("Uncaught exception",e);
            request.setAttribute("exception", e);
            request.getRequestDispatcher("/error.xhtml").forward(request, response);
        }
}

我执行以下方法:

    <p:commandButton value="Dispatch Order" update="@form"
        action="#{orderBean.dispatchOrder()}">
    </p:commandButton>

但是,没有异常处理。

我看到日志中的错误:

May 21, 2013 6:04:32 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{orderBean.dispatchOrder()}: MyException.....

我做错了什么?

推荐答案

这个老问题针对JSF 1.x,答案不适用当你发送一个JSF 2.x的ajax请求。您只能在 ajax =false添加到< p:commandButton> 或使用没有< f:ajax> 的标准JSF < h:commandButton> 为了处理ajax请求的异常,您需要一个自定义的。

That old question was targeted on JSF 1.x and the answer is not applicable when you send a JSF 2.x ajax request. Your filter will only be invoked when you add ajax="false" to the <p:commandButton> or use the standard JSF <h:commandButton> without <f:ajax>. In order to handle exceptions on ajax requests, you need a custom ExceptionHandler.



  • What is the correct way to deal with JSF 2.0 exceptions for AJAXified components?

这篇关于JSF中未捕获异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:51