diff options
author | Artur Signell <artur.signell@itmill.com> | 2009-06-08 19:14:59 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2009-06-08 19:14:59 +0000 |
commit | 09e6bffa8d7925931a8f557c5edd54656c4e5aeb (patch) | |
tree | 00b2db6f91b47b93ee241ab8632d6e25d78e2ae7 /src | |
parent | 1845ff5e7341eff535e719eeb83446cd65c38a8b (diff) | |
download | vaadin-framework-09e6bffa8d7925931a8f557c5edd54656c4e5aeb.tar.gz vaadin-framework-09e6bffa8d7925931a8f557c5edd54656c4e5aeb.zip |
Fix for #3015 - Class Object instances should not be used as identifiers, are not serializable
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
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/data/util/IndexedContainer.java | 12 | ||||
-rw-r--r-- | src/com/vaadin/ui/Form.java | 8 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java index 617fe93e14..60686abe22 100644 --- a/src/com/vaadin/data/util/IndexedContainer.java +++ b/src/com/vaadin/data/util/IndexedContainer.java @@ -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 */ /** diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index 393c94cf9e..1741fe591f 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -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()); |