3

例外をスローできるボタンの例を次に示します。

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

ExceptionHandlerは持っています:

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

(上記の例のように)使用<h:commandButton>して例外が発生すると、リダイレクトが実行され、エラーページが表示されます。を使用する<p:commandButton>と、(行が実行されても)リダイレクトは行われずredirect("error.xhtml")、何も起こらなかったかのように同じページにとどまります。例外は myExceptionHandlerでキャッチされますが、JSF エラー ページが表示されません。

これはどのように発生し、どうすれば解決できますか?

4

1 に答える 1

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-05-13T07:31:53.997 に答える