ExceptionHandler in backing bean

UI Components for JSF
Post Reply
cwerner
Posts: 1
Joined: 18 Mar 2014, 12:07

09 Jul 2014, 14:00

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.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

09 Jul 2014, 14:33

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);
            }
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

ragav
Posts: 4
Joined: 02 Jun 2014, 21:28

23 Jul 2014, 18:52

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.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 58 guests