Exception handling in JSF ajax requests -


how handle exception , access stack trace when exception thrown while processing jsf ajax request? right now, exception class name , message in javascript alert when jsf project stage set development. worse, there's no visual feedback whatsoever when jsf project stage set production, , server log doesn't show information exception.

if that's relevant, i'm using glassfish in netbeans.

this problem known , fleshed out in among others omnifaces fullajaxexceptionhandler showcase.

basically, need create custom exceptionhandler standard jsf doesn't provide 1 out box (at least, not sensible one). therein able hands on exception instance causing trouble.

here's kickoff example:

public class yourexceptionhandler extends exceptionhandlerwrapper {      private exceptionhandler wrapped;      public yourexceptionhandler(exceptionhandler wrapped) {         this.wrapped = wrapped;     }      @override     public void handle() throws facesexception {         facescontext facescontext = facescontext.getcurrentinstance();          (iterator<exceptionqueuedevent> iter = getunhandledexceptionqueuedevents().iterator(); iter.hasnext();) {             throwable exception = iter.next().getcontext().getexception(); // there is!              // thing it. example implementation merely prints stack trace.             exception.printstacktrace();              // redirect error page (bad practice).             // or render full error page (as omnifaces does).             // or show fatal faces message.             // or trigger oncomplete script.             // etc..         }          getwrapped().handle();     }      @override     public exceptionhandler getwrapped() {         return wrapped;     }  } 

in order run, create custom exceptionhandlerfactory follows:

public class yourexceptionhandlerfactory extends exceptionhandlerfactory {      private exceptionhandlerfactory parent;      public yourexceptionhandlerfactory(exceptionhandlerfactory parent) {         this.parent = parent;     }      @override     public exceptionhandler getexceptionhandler() {         return new yourexceptionhandler(parent.getexceptionhandler());     }  } 

which needs registered in faces-config.xml follows:

<factory>     <exception-handler-factory>com.example.yourexceptionhandlerfactory</exception-handler-factory> </factory> 

see also:


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -