0

我正在使用 FullAjaxExceptionHandler 来处理 ajax 请求中的超时问题。我面临的问题是处理 javax.faces.view.facelets.FaceletException。如果我在 xhtml 页面中有错误,我不想显示堆栈跟踪而是显示错误页面。这是我通过在 web.xml 中指定错误页面来实现的。问题是我想记录这个错误。我将 log4j 用于其他异常,但如何为 FaceletException 编写处理程序。如果编写另一个异常处理程序,我应该指定处理程序类的顺序,因为我已经在使用 FullAjaxExceptionHandler。

面孔-config.xml:

<application>
    <el-resolver>
        org.springframework.web.jsf.el.SpringBeanFacesELResolver
    </el-resolver>
</application>
<factory>
    <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>
<render-kit>
    <renderer>
        <component-family>org.primefaces</component-family>
        <renderer-type>org.primefaces.component.ScheduleRenderer</renderer-type>
        <renderer-class>com.example.domain.web.custom.MyScheduleRenderrer</renderer-class>
    </renderer>
</render-kit>
4

2 回答 2

0

不幸的是,您似乎不能同时拥有两者。

  • 从 JSF 规范中,ExceptionHandlerFactory期望配置单一类型
  • 从 的来源来看FullAjaxExceptionHandler,如果异常是非 ajax 的,它会被重新抛出,由<error-page>机制处理。

您必须扩展或包装FullAjaxExceptionHandler以提供 Ajax 和非 Ajax 异常处理

于 2014-02-10T16:17:05.023 回答
0

在 faces-config.xml 中添加自定义异常处理程序工厂

<application>
    <el-resolver>
        org.springframework.web.jsf.el.SpringBeanFacesELResolver
    </el-resolver>
</application>
<factory>
    <exception-handler-factory>com.fetchinglife.domain.web.permissions.CustomExceptionHandlerFactory</exception-handler-factory>
</factory>

创建自定义异常处理程序工厂

public class CustomExceptionHandlerFactory extends ExceptionHandlerFactory{

private ExceptionHandlerFactory wrapped;

public CustomExceptionHandlerFactory(ExceptionHandlerFactory wrapped) {
    this.wrapped = wrapped;
}

@Override
public ExceptionHandler getExceptionHandler() {
    return new CustomExceptionHandler(wrapped.getExceptionHandler());
}

@Override
public ExceptionHandlerFactory getWrapped() {
    return wrapped;
}

}

创建自定义异常处理程序

public class CustomExceptionHandler extends FullAjaxExceptionHandler{

static Logger log = Logger
        .getLogger(CustomExceptionHandler.class);

public CustomExceptionHandler(ExceptionHandler wrapped) {
    super(wrapped);
}

@Override
public void handle() throws FacesException {
    Iterator<ExceptionQueuedEvent> unhandledExceptionQueuedEvents = getUnhandledExceptionQueuedEvents().iterator();
    if(unhandledExceptionQueuedEvents.hasNext()){
        Throwable exception = unhandledExceptionQueuedEvents.next().getContext().getException();
        log.error("FL Error",exception);
    }
    super.handle();
}

}

于 2014-02-11T06:11:49.970 回答