Search in sources :

Example 46 with RenderPageRequestHandler

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

the class PageInstanceMapper method mapHandler.

/**
 * @see org.apache.wicket.request.IRequestMapper#mapHandler(org.apache.wicket.request.IRequestHandler)
 */
@Override
public Url mapHandler(IRequestHandler requestHandler) {
    PageComponentInfo info = null;
    if (requestHandler instanceof RenderPageRequestHandler) {
        IRequestablePage page = ((RenderPageRequestHandler) requestHandler).getPage();
        PageInfo i = new PageInfo(page.getPageId());
        info = new PageComponentInfo(i, null);
    } else if (requestHandler instanceof ListenerRequestHandler) {
        ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
        IRequestablePage page = handler.getPage();
        String componentPath = handler.getComponentPath();
        Integer renderCount = null;
        if (handler.includeRenderCount()) {
            renderCount = page.getRenderCount();
        }
        PageInfo pageInfo = new PageInfo(page.getPageId());
        ComponentInfo componentInfo = new ComponentInfo(renderCount, componentPath, handler.getBehaviorIndex());
        info = new PageComponentInfo(pageInfo, componentInfo);
    }
    if (info != null) {
        Url url = new Url();
        url.getSegments().add(getContext().getNamespace());
        url.getSegments().add(getContext().getPageIdentifier());
        encodePageComponentInfo(url, info);
        return url;
    } else {
        return null;
    }
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 47 with RenderPageRequestHandler

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

the class AbstractBookmarkableMapper method processHybrid.

/**
 * Creates a {@code IRequestHandler} that processes a hybrid request. When the page identified
 * by {@code pageInfo} was not available, the request should be treated as a bookmarkable
 * request.
 *
 * @param pageInfo
 * @param pageClass
 * @param pageParameters
 * @param renderCount
 * @return a {@code IRequestHandler} capable of processing the hybrid request.
 */
protected IRequestHandler processHybrid(PageInfo pageInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount) {
    PageProvider provider = new PageProvider(pageInfo.getPageId(), pageClass, pageParameters, renderCount);
    provider.setPageSource(getContext());
    checkExpiration(provider, pageInfo);
    /**
     * https://issues.apache.org/jira/browse/WICKET-5734
     */
    PageParameters constructionPageParameters = provider.hasPageInstance() ? provider.getPageInstance().getPageParameters() : new PageParameters();
    if (PageParameters.equals(constructionPageParameters, pageParameters) == false) {
        // when the resolved page by id has been created
        return new RenderPageRequestHandler(new PageProvider(pageClass, pageParameters));
    }
    return new RenderPageRequestHandler(provider);
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters)

Example 48 with RenderPageRequestHandler

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

the class BookmarkableMapperTest method encode4.

/**
 */
@Test
public void encode4() {
    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(true);
    IPageProvider provider = new PageProvider(page);
    IRequestHandler handler = new RenderPageRequestHandler(provider);
    Url url = encoder.mapHandler(handler);
    assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15&a=b&b=c", url.toString());
}
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)

Example 49 with RenderPageRequestHandler

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

the class BookmarkableMapperTest method decode1.

/**
 */
@Test
public void decode1() {
    Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME);
    IRequestHandler handler = encoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    assertEquals(PAGE_CLASS_NAME, page.getClass().getName());
    assertEquals(0, page.getPageParameters().getIndexedCount());
    assertTrue(page.getPageParameters().getNamedKeys().isEmpty());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 50 with RenderPageRequestHandler

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

the class BookmarkableMapperTest method decode2.

/**
 */
@Test
public void decode2() {
    Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/indexed1?a=b&b=c");
    IRequestHandler handler = encoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    assertEquals(PAGE_CLASS_NAME, page.getClass().getName());
    PageParameters p = page.getPageParameters();
    assertEquals(1, p.getIndexedCount());
    assertEquals("indexed1", p.get(0).toString());
    assertEquals(2, p.getNamedKeys().size());
    assertEquals("b", p.get("a").toString());
    assertEquals("c", p.get("b").toString());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) 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