Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-5209

NPE when using ComponentRenderer.renderComponent on a panel with <wicket:enclosure>

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.8.0
    • Fix Version/s: 6.9.0, 7.0.0-M1
    • Component/s: wicket
    • Labels:
      None

      Description

      Hi,

      Consider this example:
      <wicket:panel>
      <wicket:enclosure child="externalLink">
      <a wicket:id="externalLink">Link</a>
      </wicket:enclosure>
      </wicket:panel>

      When trying to render such a panel with ComponentRenderer.renderComponent, a NPE is thrown because Wicket try to render Enclosure without initializing it.

      Root cause:
      java.lang.NullPointerException
      at org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure.java:143)
      at org.apache.wicket.Component.determineVisibility(Component.java:4363)
      at org.apache.wicket.Component.internalBeforeRender(Component.java:916)
      at org.apache.wicket.Component.beforeRender(Component.java:991)
      at org.apache.wicket.Component.internalPrepareForRender(Component.java:2214)
      at org.apache.wicket.Component.render(Component.java:2303)
      at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390)
      at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554)
      at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529)
      at org.apache.wicket.MarkupContainer.renderAssociatedMarkup(MarkupContainer.java:689)
      at org.apache.wicket.markup.html.panel.AssociatedMarkupSourcingStrategy.renderAssociatedMarkup(AssociatedMarkupSourcingStrategy.java:76)
      at org.apache.wicket.markup.html.panel.PanelMarkupSourcingStrategy.onComponentTagBody(PanelMarkupSourcingStrategy.java:112)
      at org.apache.wicket.Component.internalRenderComponent(Component.java:2549)
      ... 29 more

      See the attached quickstart.

      I've looked a little into it, and it seems that RenderPage (used by ComponentRenderer to render components) is never initialized.
      Therefore the panel's children are never initialized too (see MarkupContainer l.930), and this causes Enclosure to have a null childComponent.

      Thanks.

        Activity

        Hide
        gsmet Guillaume Smet added a comment -

        Thanks Martin.

        FYI, we now use this feature a lot to generate HTML emails and PDF files using XHTMLRenderer.

        Show
        gsmet Guillaume Smet added a comment - Thanks Martin. FYI, we now use this feature a lot to generate HTML emails and PDF files using XHTMLRenderer.
        Hide
        sgleizes GLEIZES Stephane added a comment -

        See TestComponentRenderer in the quickstart.

        Show
        sgleizes GLEIZES Stephane added a comment - See TestComponentRenderer in the quickstart.

          People

          • Assignee:
            mgrigorov Martin Grigorov
            Reporter:
            sgleizes GLEIZES Stephane
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development