Permalink
Browse files

Modify the values parameter set on submit, rather than clearing and r…

…e-adding everything in it
  • Loading branch information...
1 parent 8a14a43 commit 3f62b78f224823657d09e5d93a17909637f561df @hlship committed Mar 28, 2011
@@ -15,6 +15,7 @@
package com.howardlewisship.tapx.core.components;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -70,8 +71,7 @@
{
/**
* The set of values edited by the component; this is used when rendering. When the form is submitted,
- * the values are first cleared, then repopulated with the selected values (some of which may be created
- * for the first time as part of this process).
+ * the set is modified, removing some old values and adding in some new values.
*/
@Parameter(required = true, allowNull = false, autoconnect = true)
private Set values;
@@ -312,7 +312,7 @@ protected void processSubmission(String name)
JSONArray selected = new JSONArray(request.getParameter(name));
- values.clear();
+ Set newValues = new HashSet(selected.length());
// First the values that have a server-side id.
@@ -324,8 +324,14 @@ protected void processSubmission(String name)
throw new RuntimeException(String.format("Unable to convert client value '%s' to a server-side value.",
clientValue));
- values.add(serverValue);
+ newValues.add(serverValue);
}
+
+ // Keep just what's in newValues
+ values.retainAll(newValues);
+
+ // Now add in anything in newValues that wasn't in values
+ values.addAll(newValues);
}
private List<String> toStrings(JSONArray values)

0 comments on commit 3f62b78

Please sign in to comment.