Why am I getting "The component(s) below failed to render"?

Snekse picture Snekse · Jun 19, 2012 · Viewed 8.5k times · Source

When I add a ChildPanel to a page, I get an error that states:

org.apache.wicket.WicketRuntimeException: 
The component(s) below failed to render.
A common problem is that you have added a component in code 
but forgot to reference it in the markup 
(thus the component will never be rendered).

1. [Form [Component id = myForm]]
2. [DropDownChoice [Component id = referenceType]]
3. [TextField [Component id = referenceNumber]]
4. [CheckBox [Component id = referenceReqChk]]
5. [ [Component id = saveRefNumButton]]
6. [ [Component id = cancelRefNumButton]]

    at org.apache.wicket.Page.checkRendering(Page.java:693)
    at org.apache.wicket.Page.onAfterRender(Page.java:849)
    at org.apache.wicket.markup.html.WebPage.onAfterRender(WebPage.java:213)
    at org.apache.wicket.Component.afterRender(Component.java:950)
    at org.apache.wicket.Component.render(Component.java:2298)
    at org.apache.wicket.Page.renderPage(Page.java:1041)
    at org.apache.wicket.request.handler.render.
           WebPageRenderer.renderPage(WebPageRenderer.java:105)

I can clearly see the components in question are added in the markup in my AbstractParentPanel, which my ChildPanel extends. The odd thing is, if I make the AbstractParentPanel a non-abstract class, I'm able to add that panel with no issues.

Why am I getting this error?

NOTE: I have already found the answer to this question. I'm adding it to SO to help others since I wasted more time than I should have for such a simple check. If you got burned by this message and this answer helped you, consider voting up this JIRA ticket

Answer

Snekse picture Snekse · Jun 19, 2012

Always start with the obvious and make sure the wicket:id(s) are defined in your markup. If you see the ID added in your markup, then chances are you have the following scenario:

  • You are trying to render a Component that is a child of another Component. This means your trying to render a Page or a Panel that is a subclass of a another Page or Panel.
    • e.g. Within a Page you try to call add(new ChildPanel("myChildPanel"));
  • The Component you are extending has defined and add Components with it's own markup
    • e.g. Within AbstractParentPanel you call add(new Label("myCommonLabel"));
  • The markup in the child Component failed to included some required Wicket XHTML
    • e.g. Within ChildPanel.html, you forgot to add <wicket:extend> tags or maybe even <wicket:panel> tags, or you have them not containing the components in question.