title: Wicket ListView ajax removes always removes last element in list
body: <p>I have a way to add panels in a listview. Each panel is associated with an Object of type Type. I have an 'add' and an some 'remove' AjaxSubmitLinks. Both have setDefaultFormProcessing(false) because I want non-submitted / validated values to remain when someone add or removes an element. setReuseItems(true) is set for the ListView. Please see the code snippet below.</p>
  
  <pre><code>         ListView itemContainer = new ListView&lt;Type&gt;("list", getList()) {
              @Override
              protected void populateItem(final ListItem&lt;Type&gt; listItem) {
                  final Component element = createComponent(listItem.getModel());
                  listItem.add(element);
                  listItem.add(new AjaxSubmitLink("remove") {
  
                      @Override
                      protected void onSubmit(AjaxRequestTarget target, Form&lt;?&gt; form) {
                          getList().remove(listItem.getIndex());
                          target.add(wrapper);
                      }
                  }.setDefaultFormProcessing(false));
              }
          };
          itemContainer.setReuseItems(true);
          add(itemContainer);
          add(new AjaxSubmitLink("add") {
              @Override
              protected void onSubmit(AjaxRequestTarget target, Form&lt;?&gt; form) {
                  Type object = addObject();
                  getList().add(object);
                  target.add(wrapper);
              }
  
              @Override
              public boolean isVisible() {
                  return getList().size() &lt; DSAddableField.this.max &amp;&amp; isEditable();
              }
          }.setDefaultFormProcessing(false));
  </code></pre>
  
  <p>Where wrapper contains everything, so everything is reloaded with Ajax.
  All works well, expcet no matter which remove link I click the last element is being removed. equals() method is overriden on Type based on a UUID check. I did a debug and it would seem to me that the right element is removed from the ListModel, but wrong values are sent down by the ajax response.</p>
  
  <p>How can I get this to work? I tried to remove setReuseItem(true), but than the non-saved values for list items were not reloaded. (Panels contain lot of input fields)</p>
  
  <p>Any suggestions?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I already tried to remove the object with getList().remove(listItem.getModelObject()), this was second solution but still failed.</p>
  
  <p>Regardless if I use remove by index or by modelobject the right element is being removed from the list when using debugger.</p>
  
  <p><strong>UDAPTE 2:</strong></p>
  
  <p>If I remove "final int index = listItem.getIndex();" the right element is removed opposed to the last one but when I add a new one to the list non saved inputs are cleared which is the original problem I'm trying to solve. Please advise.</p>