hudi
hudi

Reputation: 16525

Exception handling in wicket 6 into feedback panel

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

Answers (1)

svenmeier
svenmeier

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

Related Questions