问题描述
因此,在面对可怕的 javax.faces.application.ViewExpiredException
之后,我不得不环顾网络寻找适当的解决方案。幸运的是,这些解决方案随时可用,我继续采用OmniFaces ,以跳过 ViewExpiredException
$ b $ pre $ public class YourAjaxExceptionHandler extends FullAjaxExceptionHandler {
$ b $ public YourAjaxExceptionHandler(ExceptionHandler wrapped){
super(包裹);
$ b @Override
protected void logException(FacesContext上下文,Throwable异常,String位置,String消息,Object ...参数){
if(exception instanceof ViewExpiredException){
//如果异常== null,则不会记录任何跟踪。
super.logException(context,null,location,message,parameters);
}
else {
super.logException(context,exception,location,message,parameters);
$ b
创建一个工厂周围:
public class YourAjaxExceptionHandlerFactory扩展了ExceptionHandlerFactory {
private ExceptionHandlerFactory wrapped;
public YourAjaxExceptionHandlerFactory(ExceptionHandlerFactory包装){
this.wrapped = wrapped;
$ b @Override
public ExceptionHandler getExceptionHandler(){
return new YourAjaxExceptionHandler(getWrapped()。getExceptionHandler());
}
@Override
public ExceptionHandlerFactory getWrapped(){
return wrapped;
}
}
为了让它运行,注册为 faces-config.xml
通常的工厂(不要忘记删除 FullAjaxExceptionHandlerFactory $ c $
< factory>
< exception-handler-factory> com.example.YourExceptionHandlerFactory< / exception-handler-factory>
< / factory>
So after being confronted with the dreaded javax.faces.application.ViewExpiredException
, I had to go look around the internet to find the proper solution. Fortunately, the solutions are readily available and I went ahead and adopted the OmniFaces FullAjaxExceptionHandler.
Enough said, as with pretty much everything from OmniFaces, it worked wonders. But, every time I have a view expiring I am getting :
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 fine as it is handled as expected, but is there anyway to silence this exception from being printed to the server.log? This would crowd the log pretty quickly.
I am running :
Mojarra 2.1.23
PrimeFaces 4.0-SNAPSHOT
OmniFaces 1.6-SNAPSHOT-2013-07-01
on
Glassfish 3.1.2.2
As per OmniFaces 1.6, you can extend it and override the method logException()
as 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;
}
}
In order to get this to run, register it as factory in faces-config.xml
the usual way (don't forget to remove the original registration for FullAjaxExceptionHandlerFactory
):
<factory>
<exception-handler-factory>com.example.YourExceptionHandlerFactory</exception-handler-factory>
</factory>
这篇关于沉默FullAjaxExceptionHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!