]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix #5109: If more than one currently attached Paintables share the same debug id...
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>
Fri, 9 Mar 2012 12:29:24 +0000 (12:29 +0000)
committerJohannes Dahlström <johannes.dahlstrom@vaadin.com>
Fri, 9 Mar 2012 12:29:24 +0000 (12:29 +0000)
svn changeset:23209/svn branch:6.8

src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/ComponentLocator.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java

index fa5f102f5eae2eab33356831cbd1651389aea5c0..e34cd0fb8cd940cd3351ed2b0b954c0807bcae89 100644 (file)
@@ -1830,9 +1830,13 @@ public class ApplicationConnection {
             }
         }
 
-        if (configuration.useDebugIdInDOM() && uidl.getId().startsWith("PID_S")) {
-            DOM.setElementProperty(component.getElement(), "id", uidl.getId()
-                    .substring(5));
+        String id = uidl.getId();
+        if (configuration.useDebugIdInDOM() && id.startsWith("PID_")) {
+            // PIDs with a debug id have form "PID_[seq]S[debugid]" where [seq]
+            // is either empty or a sequential integer used to uniquify
+            // different Paintables having the same debug id. See #5109.
+            DOM.setElementProperty(component.getElement(), "id",
+                    id.substring(id.indexOf('S') + 1));
         }
 
         if (!visible) {
index b4489df81e3cb85e48f554698f3d90aa29934b53..b71b5fdeb54bd5ce824ba0baefdb9dbe2cc263db 100644 (file)
@@ -436,7 +436,7 @@ public class ComponentLocator {
             } else if (part.equals("")) {
                 w = client.getView();
             } else if (w == null) {
-                // Must be static pid (PID_S*)
+                // Must be static pid (PID_*)
                 w = (Widget) client.getPaintable(part);
             } else if (part.startsWith("domChild[")) {
                 // The target widget has been found and the rest identifies the
@@ -515,7 +515,7 @@ public class ComponentLocator {
             return false;
         }
 
-        return pid.startsWith("PID_S");
+        return pid.startsWith("PID_");
     }
 
 }
index 4454287ae994498e9df19ada47f742ccacecb5da..c0654359a17b19de6aff18c8a42914016c2f337f 100644 (file)
@@ -1997,33 +1997,28 @@ public abstract class AbstractCommunicationManager implements
         String id = paintableIdMap.get(paintable);
         if (id == null) {
             // use testing identifier as id if set
-            id = paintable.getDebugId();
-            if (id == null) {
-                id = "PID" + Integer.toString(idSequence++);
+            String debugId = paintable.getDebugId();
+            if (debugId == null) {
+                id = "PID" + idSequence++;
             } else {
-                id = "PID_S" + id;
-            }
-            Paintable old = idPaintableMap.put(id, paintable);
-            if (old != null && old != paintable) {
-                /*
-                 * Two paintables have the same id. We still make sure the old
-                 * one is a component which is still attached to the
-                 * application. This is just a precaution and should not be
-                 * absolutely necessary.
-                 */
-
-                if (old instanceof Component
-                        && ((Component) old).getApplication() != null) {
-                    throw new IllegalStateException("Two paintables ("
-                            + paintable.getClass().getSimpleName() + ","
-                            + old.getClass().getSimpleName()
-                            + ") have been assigned the same id: "
-                            + paintable.getDebugId());
+                id = "PID_S" + debugId;
+                for (int seq = 0;; ++seq) {
+                    // In case of a duplicate debug id, uniquify the PID by
+                    // inserting a sequential integer. Try successive numbers
+                    // until finding a PID that is either not used at all or
+                    // used by a detached component. See #5109.
+                    Paintable old = idPaintableMap.get(id);
+                    if (old == null
+                            || (old instanceof Component && ((Component) old)
+                                    .getApplication() == null)) {
+                        break;
+                    }
+                    id = "PID_" + seq + "S" + debugId;
                 }
             }
+            idPaintableMap.put(id, paintable);
             paintableIdMap.put(paintable, id);
         }
-
         return id;
     }