PrimeFaces with JSF - "onerror " in the <p:commandButton> doesn't work

user1553194 picture user1553194 · Jul 26, 2012 · Viewed 12.8k times · Source

I am using JSF,with @ManagedBean annotation and using Primefaces, and I got the following problem.

Why the "onerror" is not triggered? The exception just appears in my console.

login.xhtml

<p:commandButton 
     value="teste" 
     action="#{loginBean.methodTest()}" 
     ajax="true" 
     immediate="false" 
     onerror="confirmation.show()" />

<p:dialog  
    appendToBody="true" 
    header="Atencao" 
    widgetVar="confirmation"  
    showEffect="bounce">  
     ...  
</p:dialog>  

MyBean

@ManagedBean(name = "loginBean") 
@SessionScoped  
public class LoginBean {

    public void methodTest() throws Exception {
        System.out.println("hi");       
        throw new Exception("Exception Test");           
    }

Answer

Daniel picture Daniel · Jul 26, 2012

This is the expected behavior...

onerror : Client side callback to execute when ajax request fails.

in your case there is no failure in the ajax request at all , that fact that you are throwing exception got nothing to do with ajax failure

onerror is called when jsf doesn't catch your exception, http error or so. Exception != error.

read this thread for further details Ajax Engine: onerror doesn't work (might provide you with some tips...)

See the following detailed explanation about f:ajax onerror