【问题标题】:How to use FullAjaxExceptionHandler with a PrimeFaces actionListener如何将 FullAjaxExceptionHandler 与 PrimeFaces actionListener 一起使用
【发布时间】:2013-11-28 18:56:45
【问题描述】:

我对 OmniFaces 的 FullAjaxExceptionHandler 应该如何与 actionListener 提供的 PrimeFaces <p:commandButton> 一起工作感到困惑。使用常规的<h:commandButton>,错误页面会正确显示,但是使用<p:commandButton>,什么都不会发生,异常只会记录到控制台。

我的环境:PrimeFaces 4.0、GlassFish 3.1.2.2、OmniFaces 1.6.3。

查看:

<h:form>
    <p:commandButton actionListener="#{errorTester.throwRuntimeException}"
                     value="PrimeFaces" />
    <h:commandButton value="JSF"
        action="#{errorTester.throwRuntimeException}">
        <f:ajax execute="@form" render="@form" />
    </h:commandButton>
</h:form>

bean方法:

public void throwRuntimeException() {
    throw new RuntimeException("peek-a-boo");
}

如何配置&lt;p:commandButton&gt; 以获取FullAjaxExceptionHandler 处理的异常?

【问题讨论】:

    标签: jsf-2 primefaces exception-handling omnifaces


    【解决方案1】:

    主要错误是您 (ab) 使用 actionListener 进行业务操作,而这并不是故意的。您应该为此使用action

    <p:commandButton action="#{errorTester.throwRuntimeException}" 
                     value="PrimeFaces" />
    

    如果从actionListener 抛出异常,那么所有剩余的actionListeners 和action 将被跳过,JSF 将继续呈现响应。 我知道 PrimeFaces 展示中到处都是滥用 actionListeners 的商业行为,但您不应该以此为借口自己也这样做。

    另见:

    【讨论】:

    • 哦该死,对删除感到抱歉 :) 我找到了关于 action 与 actionListener 的 SO 问题,想通了,然后我真的就像“希望 BalusC 还没有开始写答案” :D
    猜你喜欢
    • 2011-09-14
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2017-03-31
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多