有没有办法在一个地方处理wicket应用程序中的所有异常
我想要这个:
// I am not sure if this is right place
this.getRequestCycleListeners().add(new AbstractRequestCycleListener() {
@Override
public IRequestHandler onException(RequestCycle cycle, Exception e) {
if (e instanceof MyException) {
// display message in feedback panel of current webPage like: getString(e.getCode())
}
//redirect to some Error page
}
});
答案 0 :(得分:2)
你走在正确的轨道上:
getRequestCycleListeners().add(new AbstractRequestCycleListener() {
@Override
public IRequestHandler onException(RequestCycle cycle, Exception e) {
MyException myE = Exceptions.findCause(e, MyException.class);
if (myE != null) {
IPageRequestHandler handler = cycle.find(IPageRequestHandler.class);
if (handler != null) {
if (handler.isPageInstanceCreated()) {
WebPage page = (WebPage)(handler.getPage());
page.error(page.getString(myE.getCode()));
return new RenderPageRequestHandler(new PageProvider(page));
}
}
return null;
}
});