3

Here's an example button which can throw an exception:

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

In my ExceptionHandler I have:

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

When I use <h:commandButton> (as above example) and an exception occurs, then redirect is executed and error page is displayed. When I use <p:commandButton>, then redirect is not happening (even though line redirect("error.xhtml") is executed) and it will stay on the same page as if nothing happened. The exception is caught in my ExceptionHandler, but JSF error page is not displayed.

How is this caused and how can I solve it?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Helija
  • 133
  • 1
  • 8
  • 2
    The technical difference is that the PrimeFaces button sends an ajax request. http://stackoverflow.com/questions/10449862/what-is-the-correct-way-to-deal-with-jsf-2-0-exceptions-for-ajaxified-components – BalusC May 09 '13 at 13:59

1 Answers1

1

As describe in link iIn BalusC comment - Omnifaces solve this problem. I remove my ExcetionHandler implementation and change to Omnifaces -> As in docs, I import omnifaces.jar, add to faces-config.xml

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

and to web.xml

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

Now I catch exception in Ajax request and redirect to error page. (tip: error.xhtml is facelet file and be careful to put correct path to it)

Helija
  • 133
  • 1
  • 8