From c19b82098d7ff9ed985201a9bce7d9c9a0df25ac Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 24 Mar 2009 08:07:50 +0000 Subject: [PATCH] Merged test case and fix for #2796: Throw an error if the same debugId is used for multiple components http://dev.itmill.com/ticket/2796 svn changeset:7139/svn branch:6.0 --- .../gwt/server/CommunicationManager.java | 19 +++++++++- .../tests/components/MultipleDebugIds.java | 35 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/com/itmill/toolkit/tests/components/MultipleDebugIds.java diff --git a/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java b/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java index 7510c401ef..16281a3c8a 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java @@ -1110,8 +1110,25 @@ public class CommunicationManager implements Paintable.RepaintRequestListener { } 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()); + } + } paintableIdMap.put(paintable, id); - idPaintableMap.put(id, paintable); } return id; diff --git a/src/com/itmill/toolkit/tests/components/MultipleDebugIds.java b/src/com/itmill/toolkit/tests/components/MultipleDebugIds.java new file mode 100644 index 0000000000..db5ba15111 --- /dev/null +++ b/src/com/itmill/toolkit/tests/components/MultipleDebugIds.java @@ -0,0 +1,35 @@ +package com.itmill.toolkit.tests.components; + +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.TextField; + +public class MultipleDebugIds extends TestBase { + + @Override + protected String getDescription() { + return "An exception should be thrown if the same debugId is assigned to several components"; + } + + @Override + protected Integer getTicketNumber() { + return 2796; + } + + @Override + protected void setup() { + TextField textField = new TextField(); + TextField textField2 = new TextField(); + Button button = new Button(); + Button button2 = new Button(); + textField.setDebugId("textfield"); + button.setDebugId("button"); + textField2.setDebugId("textfield2"); + button2.setDebugId("textfield"); + + addComponent(textField); + addComponent(textField2); + addComponent(button); + addComponent(button2); + } + +} -- 2.39.5