]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #3015 - Class Object instances should not be used as identifiers, are not...
authorArtur Signell <artur.signell@itmill.com>
Mon, 8 Jun 2009 19:14:59 +0000 (19:14 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 8 Jun 2009 19:14:59 +0000 (19:14 +0000)
Form now uses the container for generating item ids when needed.
IndexedContainer uses a counter for generating the item id.

svn changeset:8158/svn branch:6.0

src/com/vaadin/data/util/IndexedContainer.java
src/com/vaadin/ui/Form.java

index 617fe93e14774a7d039d120473d8cf379d3854cd..60686abe221ab4cac439df372688b488251757e5 100644 (file)
@@ -125,6 +125,8 @@ public class IndexedContainer implements Container.Indexed,
 
     private HashMap<Object, Object> defaultPropertyValues;
 
+    private int nextGeneratedItemId = 1;
+
     /* Container constructors */
 
     public IndexedContainer() {
@@ -305,7 +307,7 @@ public class IndexedContainer implements Container.Indexed,
     public Object addItem() {
 
         // Creates a new id
-        final Object id = new Object();
+        final Object id = generateId();
 
         // Adds the Item into container
         addItem(id);
@@ -569,7 +571,7 @@ public class IndexedContainer implements Container.Indexed,
     public Object addItemAfter(Object previousItemId) {
 
         // Creates a new id
-        final Object id = new Object();
+        final Object id = generateId();
 
         return addItemAfter(previousItemId, id);
     }
@@ -660,7 +662,7 @@ public class IndexedContainer implements Container.Indexed,
     public Object addItemAt(int index) {
 
         // Creates a new id
-        final Object id = new Object();
+        final Object id = generateId();
 
         // Adds the Item into container
         addItemAt(index, id);
@@ -668,6 +670,10 @@ public class IndexedContainer implements Container.Indexed,
         return id;
     }
 
+    private Serializable generateId() {
+        return new Integer(nextGeneratedItemId++);
+    }
+
     /* Event notifiers */
 
     /**
index 393c94cf9eefabc3254e04fa93c60acaaf9ab4f8..1741fe591f18c8a6a4b6ac2ef8e4085a6334ba94 100644 (file)
@@ -836,11 +836,15 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
         newField.setItemCaptionPropertyId("desc");
         for (int i = 0; i < values.length; i++) {
             Object id = values[i];
+            final Item item;
             if (id == null) {
-                id = new Object();
+                id = newField.addItem();
+                item = newField.getItem(id);
                 newField.setNullSelectionItemId(id);
+            } else {
+                item = newField.addItem(id);
             }
-            final Item item = newField.addItem(id);
+
             if (item != null) {
                 item.getItemProperty("desc").setValue(
                         descriptions[i].toString());