由于 ViewExpiredException,从 CustomExceptionHandler 导航后显示部分响应 xml
partial-response xml displayed after navigation from CustomExceptionHandler due to ViewExpiredException
您好,我正在使用 Primefaces 4.0 开发一个 JSF 2.2.4 项目
我正在尝试使用以下步骤复制 ViewExpiredException。
-进入浏览器登录应用程序
-打开另一个选项卡,单击 p:menuitem(例如会计屏幕)
-重新启动服务器(其中一个选项卡自动重定向到登录页面)
-再次登录应用程序,然后再次单击相同的 p:menuitem
[突然浏览器显示部分响应 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();
}
}
人脸-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");
您好,我正在使用 Primefaces 4.0 开发一个 JSF 2.2.4 项目
我正在尝试使用以下步骤复制 ViewExpiredException。
-进入浏览器登录应用程序
-打开另一个选项卡,单击 p:menuitem(例如会计屏幕)
-重新启动服务器(其中一个选项卡自动重定向到登录页面)
-再次登录应用程序,然后再次单击相同的 p:menuitem [突然浏览器显示部分响应 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();
}
}
人脸-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");