wicket 6中的异常处理进入反馈面板

时间:2016-02-05 09:30:56

标签: java wicket

有没有办法在一个地方处理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 
                }
            });

1 个答案:

答案 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;
    }
});