I've tried the new ExceptionHandler tag in primefaces but it seems that I'm missing something with this tag.
Basically my code is the same as in http://www.primefaces.org/showcase/ui/misc/exceptionHandler.xhtml , the problem is that adding this tag doesn't change anything I'm not getting any thing on client side. The standard js API is not working either with prime buttons:
jsf.ajax.addOnError(function(data) {alert('Error');})
The only difference I've noticed between my running app and Primefaces showcase is that the ajax response I get is different from the showcase's one:
My response:
showcases's response
here is the code
<h:form>
<h3 style="margin-top:0">AJAX</h3>
<p:commandButton actionListener="#{exceptionHandlerView.throwViewExpiredException}"
ajax="true"
value="Throw ViewExpiredException!" />
<p:commandButton actionListener="#{exceptionHandlerView.throwNullPointerException}"
ajax="true"
value="Throw NullPointerException!" />
<p:commandButton actionListener="#{exceptionHandlerView.throwWrappedIllegalStateException}"
ajax="true"
value="Throw IllegalStateException!" />
<h3>Non-AJAX</h3>
<p:commandButton actionListener="#{exceptionHandlerView.throwViewExpiredException}"
ajax="false"
value="Throw ViewExpiredException!" />
<p:commandButton actionListener="#{exceptionHandlerView.throwNullPointerException}"
ajax="false"
value="Throw NullPointerException!" />
<p:ajaxExceptionHandler type="javax.faces.application.ViewExpiredException"
update="exceptionDialog"
onexception="PF('exceptionDialog').show();" />
<p:ajaxExceptionHandler type="java.lang.NullPointerException"
update="exceptionDialog"
onexception="PF('exceptionDialog').show();" />
<p:dialog id="exceptionDialog" header="Exception '#{pfExceptionHandler.type}' occured!" widgetVar="exceptionDialog"
height="500px">
Message: #{pfExceptionHandler.message} <br/>
StackTrace: <h:outputText value="#{pfExceptionHandler.formattedStackTrace}" escape="false" /> <br />
<p:button onclick="document.location.href = document.location.href;"
value="Reload!"
rendered="#{pfExceptionHandler.type == 'javax.faces.application.ViewExpiredException'}" />
</p:dialog>
package org.primefaces.showcase.view.misc;
import javax.faces.FacesException;
import javax.faces.application.ViewExpiredException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
@ManagedBean
@RequestScoped
public class ExceptionHandlerView {
public void throwNullPointerException() {
throw new NullPointerException("A NullPointerException!");
}
public void throwWrappedIllegalStateException() {
Throwable t = new IllegalStateException("A wrapped IllegalStateException!");
throw new FacesException(t);
}
public void throwViewExpiredException() {
throw new ViewExpiredException("A ViewExpiredException!",
FacesContext.getCurrentInstance().getViewRoot().getViewId());
}
}
Open the by you given showcase link once again. Now click the Documentation tab. You'll see among others:
11.3 Exception Handler
PrimeFaces provides a built-in exception handler to take care of exceptions in ajax and non-ajax requests easily.
Configuration
ExceptionHandler and an ElResolver configured is required in faces configuration file.
<application> <el-resolver> org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver </el-resolver> </application> <factory> <exception-handler-factory> org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory </exception-handler-factory> </factory>
Act accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With