Question

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?

Was it helpful?

Solution

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:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top