Search in sources :

Example 11 with ListenerRequestHandler

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

the class MountedMapper method mapHandler.

@Override
public Url mapHandler(IRequestHandler requestHandler) {
    Url url = super.mapHandler(requestHandler);
    if (url == null && requestHandler instanceof ListenerRequestHandler && getRecreateMountedPagesAfterExpiry()) {
        ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
        IRequestablePage page = handler.getPage();
        if (checkPageInstance(page)) {
            Integer renderCount = null;
            if (handler.includeRenderCount()) {
                renderCount = page.getRenderCount();
            }
            String componentPath = handler.getComponentPath();
            PageInfo pageInfo = getPageInfo(handler);
            ComponentInfo componentInfo = new ComponentInfo(renderCount, componentPath, handler.getBehaviorIndex());
            PageComponentInfo pageComponentInfo = new PageComponentInfo(pageInfo, componentInfo);
            PageParameters parameters = newPageParameters();
            parameters.mergeWith(page.getPageParameters());
            UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), parameters.mergeWith(handler.getPageParameters()));
            url = buildUrl(urlInfo);
        }
    }
    return url;
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) 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) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 12 with ListenerRequestHandler

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

the class PageInstanceMapper method mapRequest.

/**
 * @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
 */
@Override
public IRequestHandler mapRequest(Request request) {
    if (matches(request)) {
        Url url = request.getUrl();
        PageComponentInfo info = getPageComponentInfo(url);
        if (info != null && info.getPageInfo().getPageId() != null) {
            Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;
            if (info.getComponentInfo() == null) {
                PageProvider provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
                provider.setPageSource(getContext());
                // render page
                return new RenderPageRequestHandler(provider);
            } else {
                ComponentInfo componentInfo = info.getComponentInfo();
                PageAndComponentProvider provider = new PageAndComponentProvider(info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());
                provider.setPageSource(getContext());
                return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
            }
        }
    }
    return null;
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 13 with ListenerRequestHandler

use of org.apache.wicket.core.request.handler.ListenerRequestHandler 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 14 with ListenerRequestHandler

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

the class BaseWicketTester method executeListener.

/**
 * Simulates processing URL that invokes an {@link IRequestListener} on	a component.
 *
 * After the listener is invoked the page containing the component will be rendered
 * (with an optional redirect - depending on {@link RenderStrategy}).
 *
 * @param component
 * @param listener
 */
public void executeListener(final Component component) {
    Args.notNull(component, "component");
    // there are two ways to do this. RequestCycle could be forced to call the handler
    // directly but constructing and parsing the URL increases the chance of triggering bugs
    Page page = component.getPage();
    PageAndComponentProvider pageAndComponentProvider = new PageAndComponentProvider(page, component);
    IRequestHandler handler = null;
    if (page.isPageStateless() || (page.isBookmarkable() && page.wasCreatedBookmarkable())) {
        handler = new BookmarkableListenerRequestHandler(pageAndComponentProvider);
    } else {
        handler = new ListenerRequestHandler(pageAndComponentProvider);
    }
    Url url = urlFor(handler);
    request.setUrl(url);
    // Process the request
    processRequest(request, null);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) Url(org.apache.wicket.request.Url)

Example 15 with ListenerRequestHandler

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

the class BaseWicketTester method invokeListener.

/**
 * Simulates invoking an {@link IRequestListener} on a component. As opposed to the
 * {@link #executeListener(Component)} method, current request/response objects will be used
 *
 * After the listener is invoked the page containing the component will be rendered
 * (with an optional redirect - depending on {@link RenderStrategy}).
 *
 * @param component
 * @param listener
 */
public void invokeListener(final Component component) {
    Args.notNull(component, "component");
    // there are two ways to do this. RequestCycle could be forced to call the handler
    // directly but constructing and parsing the URL increases the chance of triggering bugs
    IRequestHandler handler = new ListenerRequestHandler(new PageAndComponentProvider(component.getPage(), component));
    processRequest(handler);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)

Aggregations

ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)30 IRequestHandler (org.apache.wicket.request.IRequestHandler)25 Url (org.apache.wicket.request.Url)25 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)22 Test (org.junit.Test)21 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)16 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)12 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)5 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)5 MockPage (org.apache.wicket.MockPage)4 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)4 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)4 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)3 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)2 Page (org.apache.wicket.Page)1 IPageAndComponentProvider (org.apache.wicket.core.request.handler.IPageAndComponentProvider)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 RequestSettingRequestHandler (org.apache.wicket.core.request.handler.RequestSettingRequestHandler)1 WebPage (org.apache.wicket.markup.html.WebPage)1 Request (org.apache.wicket.request.Request)1