Silence FullAjaxExceptionHandler

Therefore, faced with the terrible javax.faces.application.ViewExpiredException , I had to search around the Internet to find a suitable solution. Fortunately, the solutions are easily accessible, and I went ahead and accepted the OmniFaces FullAjaxExceptionHandler .

Suffice it to say that, as in most cases from OmniFaces, it worked wonders. But every time I run out of visibility, I get:

 SEVERE: WebModule[/myModule]FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/WEB-INF/errorpages/test.xhtml' will be shown. javax.faces.application.ViewExpiredException: viewId:/my/page.xhtml - View /my/page.xhtml could not be restored. ... 

This is normal since it is handled as expected, but is there anyway to disable this exception from printing on the .log server ? It would very quickly score a magazine.

I'm runing:
Mojarra 2.1.23
PrimeFaces 4.0-SNAPSHOT
OmniFaces 1.6-SNAPSHOT-2013-07-01

on the
Glassfish 3.1.2.2

+6
source share
1 answer

According to OmniFaces 1.6, you can extend it and override the logException() method, as shown below, to skip the stack trace for ViewExpiredException .

 public class YourAjaxExceptionHandler extends FullAjaxExceptionHandler { public YourAjaxExceptionHandler(ExceptionHandler wrapped) { super(wrapped); } @Override protected void logException(FacesContext context, Throwable exception, String location, String message, Object... parameters) { if (exception instanceof ViewExpiredException) { // With exception==null, no trace will be logged. super.logException(context, null, location, message, parameters); } else { super.logException(context, exception, location, message, parameters); } } } 

Create a factory around it:

 public class YourAjaxExceptionHandlerFactory extends ExceptionHandlerFactory { private ExceptionHandlerFactory wrapped; public YourAjaxExceptionHandlerFactory(ExceptionHandlerFactory wrapped) { this.wrapped = wrapped; } @Override public ExceptionHandler getExceptionHandler() { return new YourAjaxExceptionHandler(getWrapped().getExceptionHandler()); } @Override public ExceptionHandlerFactory getWrapped() { return wrapped; } } 

To run it, register it as a factory in faces-config.xml usual way (remember to remove the original registration for FullAjaxExceptionHandlerFactory ):

 <factory> <exception-handler-factory>com.example.YourExceptionHandlerFactory</exception-handler-factory> </factory> 
+6
source

Source: https://habr.com/ru/post/950848/


All Articles