【问题标题】:p:commandButton don't redirect when ExternalContext#redirect() is calledp:commandButton 在调用 ExternalContext#redirect() 时不重定向
【发布时间】:2013-05-04 00:33:40
【问题描述】:

这是一个可以抛出异常的示例按钮:

<h:commandButton value="save" update=":formTable:tableData">
    <f:setPropertyActionListener value="BTN_ONE"
        target="#{tamplateTableBean.buttonSelected}" />
</h:commandButton>

在我的ExceptionHandler 我有:

FacesContext.getCurrentInstance().getExternalContext().redirect("error.xhtml");

当我使用&lt;h:commandButton&gt;(如上例)并发生异常时,将执行重定向并显示错误页面。 当我使用&lt;p:commandButton&gt; 时,不会发生重定向(即使执行了redirect("error.xhtml") 行),它将保持在同一页面上,就好像什么都没发生一样。在我的ExceptionHandler 中捕获到异常,但是没有显示 JSF 错误页面。

这是怎么引起的,我该如何解决?

【问题讨论】:

标签: jsf redirect primefaces commandbutton exceptionhandler


【解决方案1】:

如链接 iIn BalusC 评论中所述 - Omnifaces 解决了这个问题。我删除了我的 ExcetionHandler 实现并更改为 Omnifaces -> 与文档一样,我导入 omnifaces.jar,添加到 faces-config.xml

<factory>
  <exception-handler-factory>
     org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory
  </exception-handler-factory>
</factory> 

到 web.xml

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

现在我在 Ajax 请求中捕获异常并重定向到错误页面。 (提示:error.xhtml 是 facelet 文件,请注意输入正确的路径)

【讨论】:

    猜你喜欢
    • 2013-02-10
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 2012-05-15
    • 2014-12-22
    相关资源
    最近更新 更多