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

ListView removeLink method should remove items from list based on item index

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.4.9
    • 1.4.10, 1.5-M1
    • wicket
    • None

    Description

      In org.apache.wicket.markup.html.list.ListView the removeLink() method removes and object from the underlying list using the modelObject. instead it should remove using the item.getIndex().

      Reason: if the listview's model contains several nulls, and the clicked item's object is null then the first null would get removed instead of the entry at the item that was actually clicked.

      Instead of: 'final int oldIndex = getList().indexOf(item.getModelObject());' use the passed in item.getIndex()

      Example:

      public void onClick()
      {
      addStateChange(new Change()
      {
      private static final long serialVersionUID = 1L;

      final int oldIndex = item.getIndex()); <- Change here ///////////////////////////////
      final T removedObject = item.getModelObject();

      @Override
      public void undo()

      { ((List<T>)getList()).add(oldIndex, removedObject); }

      });

      item.modelChanging();

      // Remove item and invalidate listView
      getList().remove(oldIndex); <- Change here ///////////////////////////////

      ListView.this.modelChanged();
      ListView.this.removeAll();
      }

      I spoke with Jeremy Thomerson about this. Please assign to him. The moveUpLink and MoveDownLink are similarly affected.

      Attachments

        1. quickstart.tar.gz
          4 kB
          Jeremy Thomerson

        Activity

          People

            jthomerson Jeremy Thomerson
            checketts Clint Checketts
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: