Example usage for org.apache.wicket Page startComponentRender

List of usage examples for org.apache.wicket Page startComponentRender

Introduction

In this page you can find the example usage for org.apache.wicket Page startComponentRender.

Prototype

final void startComponentRender(Component component) 

Source Link

Document

This method is called when a component will be rendered as a part.

Usage

From source file:com.conwax.ajax.SimpleAjaxRequestTarget.java

License:Apache License

public void respond(IRequestCycle requestCycle) {
    final WebResponse response = (WebResponse) requestCycle.getResponse();

    response.reset();/*from  w ww . ja va  2 s .  c o  m*/
    // Make sure it is not cached by a client
    response.disableCaching();

    if (component.getRenderBodyOnly() == true) {
        throw new IllegalStateException(
                "Ajax render cannot be called on component that has setRenderBodyOnly enabled. Component: "
                        + component.toString());
    }

    component.setOutputMarkupId(true);

    // Initialize temporary variables
    final Page page = component.findParent(Page.class);
    if (page == null) {
        // dont throw an exception but just ignore this component,
        // somehow
        // it got removed from the page.
        LOG.debug("component: " + component + " with markupid: " + component.getMarkupId()
                + " not rendered because it was already removed from page");
        return;
    }

    page.startComponentRender(component);

    try {
        component.prepareForRender();

        // render any associated headers of the component
        // forget about Header Contribs
        // writeHeaderContribution(response, component);
    } catch (RuntimeException e) {
        try {
            component.afterRender();
        } catch (RuntimeException e2) {
            // ignore this one could be a result off.
        }
        throw e;
    }

    try {
        component.render();
    } catch (RuntimeException e) {
        response.reset();
        throw e;
    }

    page.endComponentRender(component);

}

From source file:com.wiquery.plugins.jqgrid.component.XMLDataRequestTarget.java

License:Apache License

/**
 * //from   ww w  .j  a  v a 2s  . c o  m
 * @param response
 * @param markupId
 *            id of client-side dom element
 * @param component
 *            component to render
 */
private void respondComponent(final Response response, final String markupId, final Component component,
        StringBuffer writer) {
    if (component.getRenderBodyOnly() == true) {
        throw new IllegalStateException(
                "Ajax render cannot be called on component that has setRenderBodyOnly enabled. Component: "
                        + component.toString());
    }

    component.setOutputMarkupId(true);

    // substitute our encoding response for the real one so we can capture
    // component's markup in a manner safe for transport inside CDATA block
    final Response originalResponse = response;
    encodingBodyResponse.reset();
    RequestCycle.get().setResponse(encodingBodyResponse);

    // Initialize temporary variables
    final Page page = component.findParent(Page.class);
    if (page == null) {
        // dont throw an exception but just ignore this component, somehow
        // it got
        // removed from the page.
        // throw new IllegalStateException(
        // "Ajax request attempted on a component that is not associated
        // with a Page");
        LOG.debug("component: " + component + " with markupid: " + markupId
                + " not rendered because it was already removed from page");
        return;
    }

    page.startComponentRender(component);

    try {
        component.prepareForRender();

        // render any associated headers of the component
        respondHeaderContribution(response, component, writer);
    } catch (RuntimeException e) {
        try {
            component.afterRender();
        } catch (RuntimeException e2) {
            // ignore this one could be a result off.
        }
        // Restore original response
        RequestCycle.get().setResponse(originalResponse);
        encodingBodyResponse.reset();
        throw e;
    }

    try {
        component.renderComponent();
    } catch (RuntimeException e) {
        RequestCycle.get().setResponse(originalResponse);
        encodingBodyResponse.reset();
        throw e;
    }

    page.endComponentRender(component);

    // Restore original response
    RequestCycle.get().setResponse(originalResponse);

    writer.append("<component id=\"");
    writer.append(markupId);
    writer.append("\" ");
    if (encodingBodyResponse.isContentsEncoded()) {
        writer.append(" encoding=\"");
        writer.append(getEncodingName());
        writer.append("\" ");
    }
    writer.append("><![CDATA[");
    writer.append(encodingBodyResponse.getContents());
    writer.append("]]></component>");

    encodingBodyResponse.reset();
}

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();
    page.startComponentRender(this);
    try {// w  w  w.ja  v  a  2 s.co m
        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.wicketstuff.poi.excel.TableParser.java

License:Apache License

/**
 * Mock a request to table component and return its response.
 *
 * @param tableComponent//from   w w  w  . jav a 2s  .c  o m
 * @return
 */
private BufferedWebResponse doRequest(Component tableComponent) {
    originalResponse = RequestCycle.get().getResponse();
    BufferedWebResponse mockResponse = new BufferedWebResponse(null);
    RequestCycle.get().setResponse(mockResponse);
    Application.get().getComponentPreOnBeforeRenderListeners().add(PathSetupListener.INSTANCE);
    Page page = tableComponent.getPage();
    page.startComponentRender(tableComponent);
    tableComponent.prepareForRender();
    tableComponent.render();
    return mockResponse;
}

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

License:Apache License

@Override
protected void writeComponent(final Response response, final String markupId, final Component component,
        final String encoding) {
    if (component.getRenderBodyOnly() == true) {
        throw new IllegalStateException(
                "Ajax render cannot be called on component that has setRenderBodyOnly enabled. Component: "
                        + component.toString());
    }/*from w  w w .j  a  v a  2s .  com*/
    component.setOutputMarkupId(true);
    // substitute our encoding response for the real one so we can capture
    // component's markup in a manner safe for transport inside CDATA block
    encodingBodyResponse.reset();
    RequestCycle.get().setResponse(encodingBodyResponse);
    // Initialize temporary variables
    final Page page = component.findParent(Page.class);
    if (page == null) {
        // dont throw an exception but just ignore this component, somehow
        // it got removed from the page.
        AbstractGwtAjaxResponse.LOG.debug("component: " + component + " with markupid: " + markupId
                + " not rendered because it was already removed from page");
        return;
    }
    page.startComponentRender(component);
    try {
        component.prepareForRender();
        // render any associated headers of the component
        writeHeaderContribution(response, component);
    } catch (final RuntimeException e) {
        try {
            component.afterRender();
        } catch (final RuntimeException e2) {
            // ignore this one could be a result off.
        }
        // Restore original response
        RequestCycle.get().setResponse(response);
        encodingBodyResponse.reset();
        throw e;
    }
    try {
        component.render();
    } catch (final RuntimeException e) {
        RequestCycle.get().setResponse(response);
        encodingBodyResponse.reset();
        throw e;
    }
    page.endComponentRender(component);
    // Restore original response
    RequestCycle.get().setResponse(response);
    response.write("<component id=\"");
    response.write(markupId);
    response.write("\" ");
    //        if (encodingBodyResponse.isContentsEncoded()) {
    //            response.write(" encoding=\"");
    //            response.write(getEncodingName());
    //            response.write("\" ");
    //        }
    response.write(" encoding=\"escaped-xml\" >");
    response.write(XmlUtil.escXml(encodingBodyResponse.getContents()));
    response.write("</component>");
    encodingBodyResponse.reset();
}