Search in sources :

Example 6 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class BaseWicketTester method startPage.

/**
 * Renders the page specified by given {@link IPageProvider}. After render the page instance can
 * be retrieved using {@link #getLastRenderedPage()} and the rendered document will be available
 * in {@link #getLastResponse()}.
 *
 * Depending on {@link RenderStrategy} invoking this method can mean that a redirect will happen
 * before the actual render.
 *
 * @param pageProvider
 * @return last rendered page
 */
public Page startPage(final IPageProvider pageProvider) {
    // should be null for Pages
    componentInPage = null;
    // prepare request
    request.setURL(request.getContextPath() + request.getServletPath() + "/");
    IRequestHandler handler = new RenderPageRequestHandler(pageProvider);
    // process request
    processRequest(request, handler);
    // The page rendered
    return getLastRenderedPage();
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler)

Example 7 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class AbstractBookmarkableMapper method processBookmarkable.

/**
 * Creates a {@code IRequestHandler} that processes a bookmarkable request.
 *
 * @param pageClass
 * @param pageParameters
 * @return a {@code IRequestHandler} capable of processing the bookmarkable request.
 */
protected IRequestHandler processBookmarkable(Class<? extends IRequestablePage> pageClass, PageParameters pageParameters) {
    PageProvider provider = new PageProvider(pageClass, pageParameters);
    provider.setPageSource(getContext());
    return new RenderPageRequestHandler(provider);
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider)

Example 8 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class AbstractBookmarkableMapper method mapHandler.

@Override
public Url mapHandler(IRequestHandler requestHandler) {
    // eliminate the need for IRequestHandlerDelegate
    while (requestHandler instanceof IRequestHandlerDelegate) {
        requestHandler = ((IRequestHandlerDelegate) requestHandler).getDelegateHandler();
    }
    if (requestHandler instanceof BookmarkablePageRequestHandler) {
        // simple bookmarkable URL with no page instance information
        BookmarkablePageRequestHandler handler = (BookmarkablePageRequestHandler) requestHandler;
        if (!checkPageClass(handler.getPageClass())) {
            return null;
        }
        PageInfo info = new PageInfo();
        UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
        return buildUrl(urlInfo);
    } else if (requestHandler instanceof RenderPageRequestHandler) {
        // possibly hybrid URL - bookmarkable URL with page instance information
        // but only allowed if the page was created by bookmarkable URL
        RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
        if (!checkPageClass(handler.getPageClass())) {
            return null;
        }
        if (handler.getPageProvider().isNewPageInstance()) {
            // no existing page instance available, don't bother creating new page instance
            PageInfo info = new PageInfo();
            UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
            return buildUrl(urlInfo);
        }
        IRequestablePage page = handler.getPage();
        if (checkPageInstance(page) && (!pageMustHaveBeenCreatedBookmarkable() || page.wasCreatedBookmarkable())) {
            PageInfo info = getPageInfo(handler);
            PageComponentInfo pageComponentInfo = new PageComponentInfo(info, null);
            UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), handler.getPageParameters());
            return buildUrl(urlInfo);
        } else {
            return null;
        }
    } else if (requestHandler instanceof BookmarkableListenerRequestHandler) {
        // request listener URL with page class information
        BookmarkableListenerRequestHandler handler = (BookmarkableListenerRequestHandler) requestHandler;
        Class<? extends IRequestablePage> pageClass = handler.getPageClass();
        if (!checkPageClass(pageClass)) {
            return null;
        }
        Integer renderCount = null;
        if (handler.includeRenderCount()) {
            renderCount = handler.getRenderCount();
        }
        PageInfo pageInfo = getPageInfo(handler);
        ComponentInfo componentInfo = new ComponentInfo(renderCount, handler.getComponentPath(), handler.getBehaviorIndex());
        PageParameters parameters = getRecreateMountedPagesAfterExpiry() ? new PageParameters(handler.getPage().getPageParameters()).mergeWith(handler.getPageParameters()) : handler.getPageParameters();
        UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(pageInfo, componentInfo), pageClass, parameters);
        return buildUrl(urlInfo);
    }
    return null;
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IRequestHandlerDelegate(org.apache.wicket.request.IRequestHandlerDelegate) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 9 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class AjaxRequestHandler method respond.

/**
 * @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
 */
@Override
public final void respond(final IRequestCycle requestCycle) {
    final RequestCycle rc = (RequestCycle) requestCycle;
    final WebResponse response = (WebResponse) requestCycle.getResponse();
    if (shouldRedirectToPage(requestCycle)) {
        // the page itself has been added to the request target, we simply issue a redirect
        // back to the page
        IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
        final String url = rc.urlFor(handler).toString();
        response.sendRedirect(url);
        return;
    }
    respondersFrozen = true;
    for (ITargetRespondListener listener : respondListeners) {
        listener.onTargetRespond(this);
    }
    final Application app = page.getApplication();
    page.send(app, Broadcast.BREADTH, this);
    // Determine encoding
    final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();
    // Set content type based on markup type for page
    update.setContentType(response, encoding);
    // Make sure it is not cached by a client
    response.disableCaching();
    final StringResponse bodyResponse = new StringResponse();
    update.writeTo(bodyResponse, encoding);
    CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
    response.write(filteredResponse);
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IRequestCycle(org.apache.wicket.request.IRequestCycle) PageProvider(org.apache.wicket.core.request.handler.PageProvider) StringResponse(org.apache.wicket.response.StringResponse) Application(org.apache.wicket.Application)

Example 10 with RenderPageRequestHandler

use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.

the class BookmarkableMapperTest method encode5.

/**
 */
@Test
public void encode5() {
    MockPage page = new MockPage(15);
    page.getPageParameters().set(0, "i1");
    page.getPageParameters().set(1, "i2");
    page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
    page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
    page.setCreatedBookmarkable(false);
    IPageProvider provider = new PageProvider(page);
    IRequestHandler handler = new RenderPageRequestHandler(provider);
    Url url = encoder.mapHandler(handler);
    // never allow bookmarkable render url for page that has not been
    // created by bookmarkable
    // URL
    assertNull(url);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) IPageProvider(org.apache.wicket.core.request.handler.IPageProvider) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)75 IRequestHandler (org.apache.wicket.request.IRequestHandler)64 Test (org.junit.Test)61 Url (org.apache.wicket.request.Url)50 PageProvider (org.apache.wicket.core.request.handler.PageProvider)36 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)32 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)19 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)16 MockPage (org.apache.wicket.MockPage)13 Request (org.apache.wicket.request.Request)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)5 IRequestMapper (org.apache.wicket.request.IRequestMapper)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)3 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)3 Page (org.apache.wicket.Page)2 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)2 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)2 WebResponse (org.apache.wicket.request.http.WebResponse)2