Tất cả các ExceptionHandlerFactory
ví dụ tôi đã đi qua cho đến nay chuyển hướng người dùng đến một trang viewExpired.jsf
trong trường hợp một ViewExpiredException
bị bắt:Tại sao sử dụng JSF ExceptionHandlerFactory thay vì chuyển hướng <error-page>?
public class ViewExpiredExceptionExceptionHandler extends ExceptionHandlerWrapper {
private ExceptionHandler wrapped;
public ViewExpiredExceptionExceptionHandler(ExceptionHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public ExceptionHandler getWrapped() {
return this.wrapped;
}
@Override
public void handle() throws FacesException {
for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
ExceptionQueuedEvent event = i.next();
ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
Throwable t = context.getException();
if (t instanceof ViewExpiredException) {
ViewExpiredException vee = (ViewExpiredException) t;
FacesContext facesContext = FacesContext.getCurrentInstance();
Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
NavigationHandler navigationHandler = facesContext.getApplication().getNavigationHandler();
try {
// Push some useful stuff to the request scope for use in the page
requestMap.put("currentViewId", vee.getViewId());
navigationHandler.handleNavigation(facesContext, null, "/viewExpired");
facesContext.renderResponse();
} finally {
i.remove();
}
}
}
// At this point, the queue will not contain any ViewExpiredEvents. Therefore, let the parent handle them.
getWrapped().handle();
}
}
Dường như với tôi rằng web.xml
cấu hình sau đây đơn giản về cơ bản là giống nhau và đơn giản hơn nhiều:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/viewExpired.jsf</location>
</error-page>
Điều này sẽ nhắc câu hỏi - tại sao một người sử dụng ExceptionHandlerFactory
?
Mã phía trên của bạn phải không? nếu không, bạn có thể ghi có nguồn không? Liên kết – Mindwin