由于ViewExpiredException,从CustomExceptionHandler导航后显示部分响应xml



嗨,我正在使用Primefaces 4.0开发JSF 2.2.4项目

我试图通过使用下面的步骤复制ViewExpiredException。

-进入浏览器登录应用程序

-打开另一个选项卡,单击p:菜单项(例如会计屏幕)

-重新启动服务器(其中一个选项卡自动重定向到登录页面)

-再次登录应用程序,然后再次单击相同的p:菜单项[突然浏览器显示部分响应xml而不是jsf页面]

XML在浏览器上显示:

<partial-response>
  <redirect url="/myapplication/denied/viewexpiredpage.jsf"/>
</partial-response>

CustomExceptionHandler.java

public class CustomExceptionHandler extends ExceptionHandlerWrapper {
private Logger logger = LoggerFactory.getLogger(CustomExceptionHandler.class);
private ExceptionHandler wrapped;
CustomExceptionHandler(ExceptionHandler exception) {
    this.wrapped = exception;
}
@Override
public ExceptionHandler getWrapped() {
    return wrapped;
}
@Override
public void handle() throws FacesException {
    FacesContext fc = FacesContext.getCurrentInstance();
    Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();
    NavigationHandler nav = fc.getApplication().getNavigationHandler();
    for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
        ExceptionQueuedEvent event = i.next();
        ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
        Throwable t = context.getException();
        try {
            if (t instanceof ViewExpiredException) {
                logger.error("Custom Exception Handler caught an error: " + t.getMessage());
                fc.setViewRoot(fc.getApplication().getViewHandler().createView(fc, "expiredpage"));
                nav.handleNavigation(fc, null, "expiredpage");
                fc.getPartialViewContext().setRenderAll(true);
                fc.renderResponse();
            }else{     
                logger.error("Custom Exception Handler caught an error: " + t.getMessage());
            }
        }finally{
            i.remove();
        }
    }
    // At this point, the queue will not contain any ViewExpiredEvents.
    // Therefore, let the parent handle them.
    getWrapped().handle();
}
}

faces-config.xml

<factory>
    <exception-handler-factory>
        com.pemc.crss.web.commons.exceptionhandler.CustomExceptionHandlerFactory
    </exception-handler-factory>
</factory>
<navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
        <from-outcome>expiredpage</from-outcome>
        <to-view-id>/denied/viewexpiredpage.jsf</to-view-id>
        <redirect />
    </navigation-case>
</navigation-rule>

ViewExpiredException在异常处理程序中被捕获,部分响应的url似乎是正确的,但出于一些奇怪的原因,为什么它显示部分响应xml而不是实际的jsf错误页面?

对于这个问题,任何帮助都将是非常感激的。谢谢!

ViewHandler#createView()不接受导航用例(您在那里的"expiredpage")。您应该使用的是实际的视图id或错误页面的相对路径:

fc.getApplication().getViewHandler().createView(fc, "/myapplication/denied/viewexpiredpage.jsf");

相关内容

  • 没有找到相关文章

最新更新