Search in sources :

Example 1 with FeedbackDelay

use of org.apache.wicket.feedback.FeedbackDelay in project wicket by apache.

the class PageAndComponentProvider method getComponent.

@Override
public IRequestableComponent getComponent() {
    if (component == null) {
        IRequestablePage page = getPageInstance();
        component = page != null ? page.get(componentPath) : null;
        if (component == null) {
            // make sure this page instance was just created so the page can be stateless
            if (page.isPageStateless()) {
                Page p = (Page) page;
                p.internalInitialize();
                // preparation of feedbacks is delayed into the render phase
                try (FeedbackDelay delay = new FeedbackDelay(p.getRequestCycle())) {
                    p.beforeRender();
                    p.markRendering(false);
                // note: no invocation of delay.onBeforeRender()
                }
                component = page.get(componentPath);
            }
        }
    }
    if (component == null) {
        throw new ComponentNotFoundException("Could not find component '" + componentPath + "' on page '" + getPageClass());
    }
    return component;
}
Also used : IRequestablePage(org.apache.wicket.request.component.IRequestablePage) FeedbackDelay(org.apache.wicket.feedback.FeedbackDelay) Page(org.apache.wicket.Page) IRequestablePage(org.apache.wicket.request.component.IRequestablePage)

Example 2 with FeedbackDelay

use of org.apache.wicket.feedback.FeedbackDelay in project wicket by apache.

the class PartialPageUpdate method writeComponents.

/**
 * Processes components added to the target. This involves attaching components, rendering
 * markup into a client side xml envelope, and detaching them
 *
 * @param response
 *      the response to write to
 * @param encoding
 *      the encoding for the response
 */
private void writeComponents(Response response, String encoding) {
    componentsFrozen = true;
    List<Component> toBeWritten = new ArrayList<>(markupIdToComponent.size());
    // delay preparation of feedbacks after all other components
    try (FeedbackDelay delay = new FeedbackDelay(RequestCycle.get())) {
        for (Component component : markupIdToComponent.values()) {
            if (!containsAncestorFor(component)) {
                if (prepareComponent(component)) {
                    toBeWritten.add(component);
                }
            }
        }
        // .. now prepare all postponed feedbacks
        delay.beforeRender();
    }
    // write components
    for (Component component : toBeWritten) {
        writeComponent(response, component.getAjaxRegionMarkupId(), component, encoding);
    }
    if (header != null) {
        RequestCycle cycle = RequestCycle.get();
        // some header responses buffer all calls to render*** until close is called.
        // when they are closed, they do something (i.e. aggregate all JS resource urls to a
        // single url), and then "flush" (by writing to the real response) before closing.
        // to support this, we need to allow header contributions to be written in the close
        // tag, which we do here:
        headerRendering = true;
        // save old response, set new
        Response oldResponse = cycle.setResponse(headerBuffer);
        headerBuffer.reset();
        // now, close the response (which may render things)
        header.getHeaderResponse().close();
        // revert to old response
        cycle.setResponse(oldResponse);
        // write the XML tags and we're done
        writeHeaderContribution(response);
        headerRendering = false;
    }
}
Also used : WebResponse(org.apache.wicket.request.http.WebResponse) Response(org.apache.wicket.request.Response) HeaderResponse(org.apache.wicket.markup.head.internal.HeaderResponse) IHeaderResponse(org.apache.wicket.markup.head.IHeaderResponse) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) IRequestCycle(org.apache.wicket.request.IRequestCycle) ArrayList(java.util.ArrayList) FeedbackDelay(org.apache.wicket.feedback.FeedbackDelay) Component(org.apache.wicket.Component)

Example 3 with FeedbackDelay

use of org.apache.wicket.feedback.FeedbackDelay in project wicket by apache.

the class Page method renderPage.

@Override
public void renderPage() {
    // page id is frozen during the render
    final boolean frozen = setFreezePageId(true);
    try {
        ++renderCount;
        // delay rendering of feedbacks after all other components
        try (FeedbackDelay delay = new FeedbackDelay(getRequestCycle())) {
            beforeRender();
            delay.beforeRender();
        }
        markRendering(true);
        render();
    } finally {
        setFreezePageId(frozen);
    }
}
Also used : FeedbackDelay(org.apache.wicket.feedback.FeedbackDelay)

Aggregations

FeedbackDelay (org.apache.wicket.feedback.FeedbackDelay)3 ArrayList (java.util.ArrayList)1 Component (org.apache.wicket.Component)1 Page (org.apache.wicket.Page)1 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)1 HeaderResponse (org.apache.wicket.markup.head.internal.HeaderResponse)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1 Response (org.apache.wicket.request.Response)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 WebResponse (org.apache.wicket.request.http.WebResponse)1