Search in sources :

Example 56 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class DefaultExceptionMapper method extractCurrentPage.

/**
 * @return the page being rendered when the exception was thrown, or {@code null} if it cannot
 *         be extracted
 */
protected Page extractCurrentPage() {
    final RequestCycle requestCycle = RequestCycle.get();
    IRequestHandler handler = requestCycle.getActiveRequestHandler();
    if (handler == null) {
        handler = requestCycle.getRequestHandlerScheduledAfterCurrent();
    }
    if (handler instanceof IPageRequestHandler) {
        IPageRequestHandler pageRequestHandler = (IPageRequestHandler) handler;
        return (Page) pageRequestHandler.getPage();
    }
    return null;
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) ExceptionErrorPage(org.apache.wicket.markup.html.pages.ExceptionErrorPage)

Example 57 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class DefaultExceptionMapper method createPageRequestHandler.

/**
 * Creates a {@link RenderPageRequestHandler} for the target page provided by {@code pageProvider}.
 *
 * Uses {@link RenderPageRequestHandler.RedirectPolicy#NEVER_REDIRECT} policy to preserve the original page's URL
 * for non-Ajax requests and {@link RenderPageRequestHandler.RedirectPolicy#AUTO_REDIRECT} for AJAX requests.
 *
 * @param pageProvider
 * 			the page provider for the target page
 * @return the request handler for the target page
 */
protected RenderPageRequestHandler createPageRequestHandler(PageProvider pageProvider) {
    RequestCycle requestCycle = RequestCycle.get();
    if (requestCycle == null) {
        throw new IllegalStateException("there is no current request cycle attached to this thread");
    }
    RenderPageRequestHandler.RedirectPolicy redirect = RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT;
    if (isProcessingAjaxRequest()) {
        redirect = RenderPageRequestHandler.RedirectPolicy.AUTO_REDIRECT;
    }
    return new RenderPageRequestHandler(pageProvider, redirect);
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 58 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class AbstractDefaultAjaxBehavior method renderHead.

/**
 * @see org.apache.wicket.behavior.AbstractAjaxBehavior#renderHead(Component,
 *      org.apache.wicket.markup.head.IHeaderResponse)
 */
@Override
public void renderHead(final Component component, final IHeaderResponse response) {
    super.renderHead(component, response);
    CoreLibrariesContributor.contributeAjax(component.getApplication(), response);
    RequestCycle requestCycle = component.getRequestCycle();
    Url baseUrl = requestCycle.getUrlRenderer().getBaseUrl();
    CharSequence ajaxBaseUrl = Strings.escapeMarkup(baseUrl.toString());
    response.render(JavaScriptHeaderItem.forScript("Wicket.Ajax.baseUrl=\"" + ajaxBaseUrl + "\";", "wicket-ajax-base-url"));
    renderExtraHeaderContributors(component, response);
}
Also used : RequestCycle(org.apache.wicket.request.cycle.RequestCycle) Url(org.apache.wicket.request.Url)

Example 59 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class AbstractDefaultAjaxBehavior method onRequest.

@Override
public final void onRequest() {
    WebApplication app = (WebApplication) getComponent().getApplication();
    AjaxRequestTarget target = app.newAjaxRequestTarget(getComponent().getPage());
    RequestCycle requestCycle = RequestCycle.get();
    requestCycle.scheduleRequestHandlerAfterCurrent(target);
    respond(target);
}
Also used : RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WebApplication(org.apache.wicket.protocol.http.WebApplication)

Example 60 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class AjaxClientInfoBehavior method onTimer.

@Override
protected final void onTimer(AjaxRequestTarget target) {
    stop(target);
    RequestCycle requestCycle = RequestCycle.get();
    IRequestParameters requestParameters = requestCycle.getRequest().getRequestParameters();
    WebClientInfo clientInfo = newWebClientInfo(requestCycle);
    clientInfo.getProperties().read(requestParameters);
    Session.get().setClientInfo(clientInfo);
    onClientInfo(target, clientInfo);
}
Also used : WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IRequestParameters(org.apache.wicket.request.IRequestParameters)

Aggregations

RequestCycle (org.apache.wicket.request.cycle.RequestCycle)69 WebResponse (org.apache.wicket.request.http.WebResponse)14 IRequestHandler (org.apache.wicket.request.IRequestHandler)9 Url (org.apache.wicket.request.Url)9 Response (org.apache.wicket.request.Response)8 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)7 BufferedWebResponse (org.apache.wicket.protocol.http.BufferedWebResponse)7 Page (org.apache.wicket.Page)6 Request (org.apache.wicket.request.Request)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)5 IRequestCycle (org.apache.wicket.request.IRequestCycle)5 AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)5 Test (org.junit.Test)5 Application (org.apache.wicket.Application)4 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)4 WebClientInfo (org.apache.wicket.protocol.http.request.WebClientInfo)4 WebRequest (org.apache.wicket.request.http.WebRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 WebApplication (org.apache.wicket.protocol.http.WebApplication)3 UrlRenderer (org.apache.wicket.request.UrlRenderer)3