Hi, I don't know if it is a proper way but this is how I did it.

1. Extended WebRequestCycle

    @Override
    public Page onRuntimeException(Page page, RuntimeException e) {
        // if error was during application running e.g. when Home page was
loaded and if it was an ajax request that caused problem
        if (page instanceof Home && RequestCycle.get().getRequestTarget()
instanceof AjaxRequestTarget) {
            // On my Home page there is a js ModalWindow into which I place
the error text
            ModalWindow errorPage = (ModalWindow)page.get("modalErrorPage");
            final ResourceModel message = new
ResourceModel("gorillaUrlError");
            errorPage.setContent( "... ");
           
errorPage.show((AjaxRequestTarget)RequestCycle.get().getRequestTarget());
        }
return null;

2. Extended WebRequestCycleProcessor to comment out placing 500 error code
into Ajax response.

    @Override
    public void respond(RuntimeException e, RequestCycle requestCycle)
    {
        // If application doesn't want debug info showing up for users
        final Application application = Application.get();
        final IExceptionSettings settings =
application.getExceptionSettings();
        final Page responsePage = requestCycle.getResponsePage();

        Page override = onRuntimeException(responsePage, e);
        if (override != null)
        {
            throw new RestartResponseException(override);
        }
        else if (e instanceof AuthorizationException)
        {
            // are authorization exceptions always thrown before the real
            // render?
            // else we need to make a page (see below) or set it hard to a
            // redirect.
            Class<? extends Page> accessDeniedPageClass =
application.getApplicationSettings()
                .getAccessDeniedPage();

            throw new
RestartResponseAtInterceptPageException(accessDeniedPageClass);
        }
        else if (e instanceof PageExpiredException)
        {
            Class<? extends Page> pageExpiredErrorPageClass =
application.getApplicationSettings()
                .getPageExpiredErrorPage();
            boolean mounted = isPageMounted(pageExpiredErrorPageClass);
            RequestCycle.get().setRedirect(mounted);
            throw new RestartResponseException(pageExpiredErrorPageClass);
        }
        else if (settings.getUnexpectedExceptionDisplay() !=
IExceptionSettings.SHOW_NO_EXCEPTION_PAGE)
        {
            // we do not want to redirect - we want to inline the error
output
            // and preserve the url so when the refresh button is pressed we
            // rerun the code that caused the error
            // However we don't what to do this in a situation where we are
in portlet mode
            if (!RequestContext.get().isPortletRequest())
            {
                requestCycle.setRedirect(false);
            }

            // figure out which error page to show
            Class<? extends Page> internalErrorPageClass =
application.getApplicationSettings()
                .getInternalErrorPage();
            Class<? extends Page> responseClass = responsePage != null ?
responsePage.getClass()
                : null;

            if (responseClass != internalErrorPageClass &&
                settings.getUnexpectedExceptionDisplay() ==
IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE)
            {
                throw new RestartResponseException(internalErrorPageClass);
            }
            else if (responseClass != ExceptionErrorPage.class)
            {
                // Show full details
                throw new RestartResponseException(new ExceptionErrorPage(e,
responsePage));
            }
            else
            {
                // give up while we're ahead!
                throw new WicketRuntimeException("Internal Error: Could not
render error page " +
                    internalErrorPageClass, e);
            }
        }
        else if (requestCycle.getResponse() instanceof WebResponse)
        {
            // commented out so that error code is not set to header
            // it was set in case of runtime Java exception and
SHOW_NO_EXCEPTION_PAGE option of application
//           
((WebResponse)requestCycle.getResponse()).getHttpServletResponse().setStatus(
//                HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }

3. Overridden 2 methods in WebApplication
public RequestCycle newRequestCycle(Request request, Response response) {
protected IRequestCycleProcessor newRequestCycleProcessor() {


That's it.
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/EXception-handling-in-Wicket-tp2340439p2340560.html
Sent from the Wicket - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to