This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Rendering Panel to a String
Skip to end of metadata
Go to start of metadata

Here is a way to render panel markup to string.

It is a bit of a tweak, I admit, but what can you do.

  1. Assume you have components on your page, ready to be rendered.
  1. In onBeforeRender, quickly switch one of your existing components to another that you want to render into a string
  1. Let your special component render into a string.
  1. Restore back to the original component that was supposed to be rendered onto the web page.
  1. It seems to work ok at least if your component is a panel.

Example code:

somewhere in your page hierarchy that is actually rendered

   * @see org.apache.wicket.Page#onBeforeRender()
  protected void onBeforeRender() {
        + MarkupUtils.renderToString(loginForm, new IntroductionPanel(loginForm.getId())));

MarkupUtils.public static String renderToString(final Component parentDonorComponent, final Component component) {
    if (!component.getId().equals(parentDonorComponent.getId())) {
      throw new IllegalStateException("Component will try to substitute parentDonorComponent to render. Donor and string render Component id's must be equal.");
    final Response originalResponse = RequestCycle.get().getResponse();
    StringResponse stringResponse = new StringResponse();
    MarkupContainer parentComponent = parentDonorComponent.getParent(); 

    try {
      try {
      } catch (RuntimeException e) {
        throw e;
    } finally {
      // Restore original component
      // Restore original response

    return stringResponse.toString();

  • No labels