Page 1 of 1

ExceptionHandler in backing bean

Posted: 09 Jul 2014, 14:00
by cwerner
Hi everybody,

I want to use <p:ajaxExceptionHandler> in my application.
Is it possible to get access to the exception of pfExceptionHandler in a backing bean?
I want to send an email in the case of an error.

Thanks for your help.

Re: ExceptionHandler in backing bean

Posted: 09 Jul 2014, 14:33
by tandraschko

Code: Select all

           ExceptionInfo info = facesContext.getApplication().evaluateExpressionGet(context, "#{pfExceptionHandler}", ExceptionInfo.class)
or

Code: Select all

            FacesContext context = FacesContext.getCurrentInstance();
            ExceptionInfo info = (ExceptionInfo) context.getAttributes().get(ExceptionInfo.ATTRIBUTE_NAME);
            
            if (info == null) {
                info = (ExceptionInfo) context.getExternalContext().getFlash().get(ExceptionInfo.ATTRIBUTE_NAME);
            }

Re: ExceptionHandler in backing bean

Posted: 23 Jul 2014, 18:52
by ragav
I'm using ajaxExceptionHandler & org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory registered in my faces-config.xml and also have few error-pages defined in web.xml.

When an ajax exception occurs my xhtml page is able to retrieve all the info from pfExceptionHandler, however in case of exception during non-ajax request, the pfExceptionHandler is getting resolved to null in the error.xhtml(which is configured as error-page in web.xml).

I tried to debug the PrimeExceptionHandlerELResolver and found that its trying to get the ExceptionInfo object from Flash scope and eventually returning null.

Code: Select all

    public Object getValue(ELContext elContext, Object base, Object property) {

        if (EL_NAME.equals(property)) {
            elContext.setPropertyResolved(true);
            
            FacesContext context = FacesContext.getCurrentInstance();
            ExceptionInfo info = (ExceptionInfo) context.getAttributes().get(ExceptionInfo.ATTRIBUTE_NAME);
            
            if (info == null) {
                info = (ExceptionInfo) context.getExternalContext().getFlash().get(ExceptionInfo.ATTRIBUTE_NAME);   // This is coming as null in my case
            }
            
            return info;
        }

        return null;
    }


Could someone please help me on this?

Note: Primefaces version : 5.0 and also I tried to retrieve the request attribute 'javax.servlet.error.exception' in my error.xhtml and even this is returned as empty.

Thanks.