Reputation: 16525
Is there a way how to handle all exception in wicket application in one place
I want this:
// 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
}
});
Upvotes: 0
Views: 759
Reputation: 5681
You're on the right track:
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;
}
});
Upvotes: 2