Search in sources :

Example 6 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class ModalWindow method getWindowOpenJavaScript.

/**
 * Returns the javascript used to open the window. Subclass
 * {@link #postProcessSettings(AppendingStringBuffer)} to modify the JavaScript if needed.
 *
 * See WICKET-12
 *
 * @return javascript that opens the window
 */
protected final String getWindowOpenJavaScript() {
    JSONObject settings = new JSONObject();
    settings.put("minWidth", getMinimalWidth());
    settings.put("minHeight", getMinimalHeight());
    settings.put("className", getCssClassName());
    settings.put("width", getInitialWidth());
    if ((isUseInitialHeight() == true) || (isCustomComponent() == false)) {
        settings.put("height", getInitialHeight());
    } else {
        settings.put("height", (Object) null);
    }
    settings.put("resizable", isResizable());
    if (isResizable() == false) {
        settings.put("widthUnit", getWidthUnit());
        settings.put("heightUnit", getHeightUnit());
    }
    if (isCustomComponent() == false) {
        Page page = createPage();
        if (page == null) {
            throw new WicketRuntimeException("Error creating page for modal dialog.");
        }
        CharSequence pageUrl;
        RequestCycle requestCycle = RequestCycle.get();
        page.getSession().getPageManager().touchPage(page);
        if (page.isPageStateless()) {
            pageUrl = requestCycle.urlFor(page.getClass(), page.getPageParameters());
        } else {
            IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
            pageUrl = requestCycle.urlFor(handler);
        }
        settings.put("src", pageUrl);
    } else {
        settings.put("element", new JSONFunction("document.getElementById(\"" + getContentMarkupId() + "\")"));
    }
    if (getCookieName() != null) {
        settings.put("cookieId", getCookieName());
    }
    String title = getTitle() != null ? getTitle().getObject() : null;
    if (title != null) {
        settings.put("title", getDefaultModelObjectAsString(title));
    }
    if (getMaskType() == MaskType.TRANSPARENT) {
        settings.put("mask", "transparent");
    } else if (getMaskType() == MaskType.SEMI_TRANSPARENT) {
        settings.put("mask", "semi-transparent");
    }
    settings.put("autoSize", autoSize);
    settings.put("unloadConfirmation", showUnloadConfirmation());
    // set true if we set a windowclosedcallback
    boolean haveCloseCallback = false;
    // notification request
    if (windowClosedCallback != null) {
        WindowClosedBehavior behavior = getBehaviors(WindowClosedBehavior.class).get(0);
        settings.put("onClose", new JSONFunction("function() { " + behavior.getCallbackScript() + " }"));
        haveCloseCallback = true;
    }
    // close window property (thus cleaning the shown flag)
    if ((closeButtonCallback != null) || (haveCloseCallback == false)) {
        CloseButtonBehavior behavior = getBehaviors(CloseButtonBehavior.class).get(0);
        settings.put("onCloseButton", new JSONFunction("function() { " + behavior.getCallbackScript() + "; return false; }"));
    }
    postProcessSettings(settings);
    AppendingStringBuffer buffer = new AppendingStringBuffer(500);
    buffer.append("var settings = ");
    buffer.append(settings.toString());
    buffer.append(";");
    buffer.append(getShowJavaScript());
    return buffer.toString();
}
Also used : AppendingStringBuffer(org.apache.wicket.util.string.AppendingStringBuffer) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Page(org.apache.wicket.Page) JSONFunction(org.apache.wicket.ajax.json.JSONFunction) JSONObject(com.github.openjson.JSONObject) PageProvider(org.apache.wicket.core.request.handler.PageProvider)

Example 7 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class RequestCycle method executeExceptionRequestHandler.

/**
 * Execute a requestHandler for the given exception.
 *
 * @param exception
 * @param retryCount
 */
private void executeExceptionRequestHandler(Exception exception, int retryCount) {
    scheduleRequestHandlerAfterCurrent(null);
    IRequestHandler handler = handleException(exception);
    if (handler == null) {
        log.error("Error during request processing. URL=" + request.getUrl(), exception);
        return;
    }
    try {
        listeners.onExceptionRequestHandlerResolved(this, handler, exception);
        execute(handler);
    } catch (Exception e) {
        if (retryCount > 0) {
            executeExceptionRequestHandler(exception, retryCount - 1);
        } else {
            log.error("Exception retry count exceeded", e);
        }
    }
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) ReplaceHandlerException(org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)

Example 8 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class RequestCycle method find.

/**
 * Finds a IRequestHandler which is either the currently executing handler or is scheduled to be
 * executed.
 *
 * @return the found IRequestHandler or {@link Optional#empty()}
 */
@SuppressWarnings("unchecked")
public <T extends IRequestHandler> Optional<T> find(final Class<T> type) {
    if (type == null) {
        return Optional.empty();
    }
    IRequestHandler result = getActiveRequestHandler();
    if (type.isInstance(result)) {
        return (Optional<T>) Optional.of(result);
    }
    result = getRequestHandlerScheduledAfterCurrent();
    if (type.isInstance(result)) {
        return (Optional<T>) Optional.of(result);
    }
    return Optional.empty();
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Optional(java.util.Optional)

Example 9 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class RequestCycle method processRequest.

/**
 * Processes the request.
 *
 * @return <code>true</code> if the request resolved to a Wicket request, <code>false</code>
 *         otherwise.
 */
public boolean processRequest() {
    try {
        set(this);
        listeners.onBeginRequest(this);
        onBeginRequest();
        IRequestHandler handler = resolveRequestHandler();
        if (handler == null) {
            // Did not find any suitable handler, thus not executing the request
            log.debug("No suitable handler found for URL {}, falling back to container to process this request", request.getUrl());
        } else {
            execute(handler);
            return true;
        }
    } catch (Exception exception) {
        executeExceptionRequestHandler(exception, getExceptionRetryCount());
        return true;
    } finally {
        set(null);
    }
    return false;
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) ReplaceHandlerException(org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)

Example 10 with IRequestHandler

use of org.apache.wicket.request.IRequestHandler in project wicket by apache.

the class RequestCycle method execute.

/**
 * Execute a request handler and notify registered {@link IRequestCycleListener}s.
 *
 * @param handler
 */
private void execute(IRequestHandler handler) {
    Args.notNull(handler, "handler");
    while (handler != null) {
        try {
            listeners.onRequestHandlerResolved(this, handler);
            IRequestHandler next = requestHandlerExecutor.execute(handler);
            listeners.onRequestHandlerExecuted(this, handler);
            handler = next;
        } catch (RuntimeException e) {
            ReplaceHandlerException replacer = Exceptions.findCause(e, ReplaceHandlerException.class);
            if (replacer == null) {
                throw e;
            }
            if (replacer.getRemoveScheduled()) {
                requestHandlerExecutor.schedule(null);
            }
            handler = replacer.getReplacementRequestHandler();
        }
    }
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IRequestHandler(org.apache.wicket.request.IRequestHandler) ReplaceHandlerException(org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)

Aggregations

IRequestHandler (org.apache.wicket.request.IRequestHandler)188 Test (org.junit.Test)159 Url (org.apache.wicket.request.Url)138 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)65 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)47 PageProvider (org.apache.wicket.core.request.handler.PageProvider)45 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)36 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)32 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)28 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)25 Request (org.apache.wicket.request.Request)25 MockPage (org.apache.wicket.MockPage)23 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)20 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)17 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)17 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)16 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)11 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)10 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)8 Page (org.apache.wicket.Page)6