title: Dynamically add components to ListView in Wicket
body: <p>I want to make a form with "Add" button. After pressing "Add" button new panel adds to the wicket ListView element. How do I do that? I want to be able add unlimited number of rows.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>InteractivePanelPage.html</strong></p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;a href="#" wicket:id="addPanelLink"&gt;Add Panel&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr wicket:id="interactiveListView"&gt;
          &lt;td&gt;
          &lt;span wicket:id="interactiveItemPanel"&gt;&lt;/span&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>InteractivePanelPage.java</strong></p>
  
  <pre><code>// ... imports
  public class InteractivePanelPage extends WebPage {
      public LinkedList&lt;InteractivePanel&gt; interactivePanels = new LinkedList&lt;InteractivePanel&gt;();
  
      private ListView&lt;InteractivePanel&gt; interactiveList;
  
      public InteractivePanelPage() {
          add(new AjaxLink&lt;String&gt;("addPanelLink") {
              private static final long serialVersionUID = 1L;
  
              @Override
              public void onClick(AjaxRequestTarget target) {
                  try {
                      System.out.println("link clicked");
  
                      InteractivePanel newInteractivePanel = new InteractivePanel(
                              "interactiveItemPanel");
                      newInteractivePanel.setOutputMarkupId(true);
  
                      interactiveList.getModelObject().add(newInteractivePanel);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
  
          interactivePanels.add(new InteractivePanel("interactiveItemPanel"));
  
          interactiveList = new ListView&lt;InteractivePanel&gt;("interactiveListView",
                  new PropertyModel&lt;List&lt;InteractivePanel&gt;&gt;(this, "interactivePanels")) {
              private static final long serialVersionUID = 1L;
  
              @Override
              protected void populateItem(ListItem&lt;InteractivePanel&gt; item) {
                  item.add(item.getModelObject());
              }
          };
  
          interactiveList.setOutputMarkupId(true);
  
          add(interactiveList);
      }
  
      public List&lt;InteractivePanel&gt; getInteractivePanels() {
          return interactivePanels;
      }
  }
  </code></pre>
  
  <p><strong>InteractivePanel.html</strong></p>
  
  <pre><code>&lt;html xmlns:wicket&gt;
  &lt;wicket:panel&gt;
  &lt;span&gt;&lt;input type="button" value="BLAAA" wicket:id="simpleButton"/&gt;&lt;/span&gt;
  &lt;/wicket:panel&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>InteractivePanel.java</strong></p>
  
  <pre><code>// ... imports
  public class InteractivePanel extends Panel {
      private static final long serialVersionUID = 1L;
  
      public InteractivePanel(String id) {
          super(id);
  
          add(new Button("simpleButton"));
      }
  }
  </code></pre>
  
  <p>This simply doesn't work. Can anybody see why? Thanks</p>