Example usage for org.apache.wicket.request.cycle RequestCycle setResponse

List of usage examples for org.apache.wicket.request.cycle RequestCycle setResponse

Introduction

In this page you can find the example usage for org.apache.wicket.request.cycle RequestCycle setResponse.

Prototype

@Override
public Response setResponse(final Response response) 

Source Link

Usage

From source file:name.martingeisse.wicket.component.tree.JsTree.java

License:Open Source License

private String renderToString() {

    // prepare string response
    final RequestCycle requestCycle = RequestCycle.get();
    final Response oldResponse = requestCycle.getResponse();
    final StringResponse newResponse = new StringResponse();
    requestCycle.setResponse(newResponse);

    // prepare rendering (I know, this calls internal Wicket API ...)
    Page page = getPage();/*from  w  w  w.ja va 2s.  c om*/
    page.startComponentRender(this);
    try {
        prepareForRender();
    } catch (RuntimeException e) {
        try {
            afterRender();
        } catch (RuntimeException e2) {
        }
        RequestCycle.get().setResponse(oldResponse);
        throw e;
    }

    // render the component
    try {
        render();
    } catch (RuntimeException e) {
        RequestCycle.get().setResponse(oldResponse);
        throw e;
    }

    // cleanup render state
    page.endComponentRender(this);

    // restore original response
    requestCycle.setResponse(oldResponse);

    return newResponse.toString();
}

From source file:org.apache.openmeetings.service.mail.template.AbstractTemplatePanel.java

License:Apache License

/**
 * Collects the html generated by the rendering of a page.
 * /*from   w w w .  j  a va  2  s.  c  o  m*/
 * @param panel
 *            the panel that should be rendered.
 * @return the html rendered by the panel
 */
protected static CharSequence renderPanel(final Panel panel) {
    RequestCycle requestCycle = RequestCycle.get();

    final Response oldResponse = requestCycle.getResponse();
    BufferedWebResponse tempResponse = new BufferedWebResponse(null);

    try {
        requestCycle.setResponse(tempResponse);

        TemplatePage page = new TemplatePage();
        page.add(panel);

        panel.render();
    } finally {
        requestCycle.setResponse(oldResponse);
    }

    return tempResponse.getText();
}

From source file:org.hippoecm.frontend.service.render.AbstractRenderService.java

License:Apache License

@Override
public void onComponentTagBody(MarkupStream markupStream, final ComponentTag openTag) {
    int beginOfBodyIndex = markupStream.getCurrentIndex();
    Response response = new StringResponse();
    RequestCycle requestCycle = getRequestCycle();
    Response webResponse = requestCycle.setResponse(response);
    try {/*from  w ww. j a v a 2 s  .  com*/
        super.onComponentTagBody(markupStream, openTag);
        webResponse.write(response.toString());
    } catch (WicketRuntimeException ex) {
        log.error("runtime plugin failure", ex);
        // this is a plugin, don't let the entire UI fail because of it failing
        markupStream.setCurrentIndex(beginOfBodyIndex);
        markupStream.skipToMatchingCloseTag(openTag);
    } finally {
        requestCycle.setResponse(webResponse);
    }
}

From source file:org.xaloon.wicket.component.render.StringWebPageRenderer.java

License:Apache License

/**
 * @param requestCycle/* ww w  .java2s.  c  o  m*/
 * @return rendered page as html code
 */
public String renderToString(RequestCycle requestCycle) {
    // get the page before checking for a scheduled request handler because
    // the page may call setResponsePage in its constructor
    IRequestablePage requestablePage = getPage();

    // keep the original response
    final WebResponse originalResponse = (WebResponse) requestCycle.getResponse();

    // buffered web response for page
    BufferedWebResponse response = new BufferedWebResponse(originalResponse);

    requestCycle.setResponse(response);
    requestablePage.renderPage();

    return response.toString();
}

From source file:sf.wicklet.gwt.server.ajax.impl.AbstractGwtAjaxResponse.java

License:Apache License

/**
 * @param response//from   www . jav a 2  s.co m
 *      the response to write to
 * @param component
 *      to component which will contribute to the header
 */
protected void writeHeaderContribution(final Response response, final Component component) {
    headerRendering = true;
    // create the htmlheadercontainer if needed
    if (header == null) {
        header = new AjaxHtmlHeaderContainer(this);
        final Page parentPage = component.getPage();
        parentPage.addOrReplace(header);
    }
    final RequestCycle requestCycle = component.getRequestCycle();
    // save old response, set new
    final Response oldResponse = requestCycle.setResponse(encodingHeaderResponse);
    try {
        encodingHeaderResponse.reset();
        // render the head of component and all it's children
        component.renderHead(header);
        if (component instanceof MarkupContainer) {
            ((MarkupContainer) component).visitChildren(new IVisitor<Component, Void>() {
                @Override
                public void component(final Component component, final IVisit<Void> visit) {
                    if (component.isVisibleInHierarchy()) {
                        component.renderHead(header);
                    } else {
                        visit.dontGoDeeper();
                    }
                }
            });
        }
    } finally {
        // revert to old response
        requestCycle.setResponse(oldResponse);
    }
    writeHeaderContribution(response);
    headerRendering = false;
}

From source file:sf.wicklet.gwt.server.ajax.impl.GwtAjaxWickletTarget.java

License:Apache License

/**
 * @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
 *//*from   ww  w  .j  av  a2  s  .c  o m*/
@Override
public final void respond(final IRequestCycle requestCycle) {
    final RequestCycle rc = (RequestCycle) requestCycle;
    final WebResponse response = (WebResponse) requestCycle.getResponse();
    if (errorResponse(response)) {
        return;
    }
    if (responseObject.containsPage()) {
        // the page itself has been added to the request target, we simply issue a redirect
        // back to the page
        final IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
        final String url = rc.urlFor(handler).toString();
        response.sendRedirect(url);
        return;
    }
    respondersFrozen = true;
    for (final 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
    responseObject.setContentType(response, encoding);
    // Make sure it is not cached by a client
    response.disableCaching();
    try {
        final StringResponse bodyResponse = new StringResponse();
        responseObject.writeTo(bodyResponse, encoding);
        final CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
        response.write(filteredResponse);
    } finally {
        // restore the original response
        rc.setResponse(response);
    }
}