2

I am confused about how OmniFaces's FullAjaxExceptionHandler should work with a PrimeFaces <p:commandButton> that is supplied with an actionListener. With a regular <h:commandButton>, the error page shows up correctly, however with a <p:commandButton>, nothing happens and the exception is only logged to console.

My environment: PrimeFaces 4.0, GlassFish 3.1.2.2, OmniFaces 1.6.3.

View:

<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>

The bean method:

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

How do I have configure the <p:commandButton> to get the exception handled by FullAjaxExceptionHandler?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Daniel Szalay
  • 4,041
  • 12
  • 57
  • 103

1 Answers1

1

The main mistake is that you're (ab)using an actionListener for business actions while that isn't intented for that. You should use the action for that.

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

If an exception is thrown from an actionListener, then all remaining actionListeners and the action will be skipped and JSF will proceed to render response. I understand that PrimeFaces showcase is cluttered with abused actionListeners for business actions over all place, but you shouldn't use that as an excuse to also do that yourself.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Oh damn, sorry about the delete :) I've found the SO question about action vs actionListener, figured it out and then I was literally like 'hope BalusC hasn't started writing an answer yet' :D – Daniel Szalay Nov 15 '13 at 12:02