summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/UI.java6
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java (renamed from server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java)2
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java65
3 files changed, 71 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java
index 31a7446e96..2878d10fa1 100644
--- a/server/src/com/vaadin/ui/UI.java
+++ b/server/src/com/vaadin/ui/UI.java
@@ -556,9 +556,13 @@ public abstract class UI extends AbstractComponentContainer implements
return this;
}
+ /**
+ * This implementation replaces a component in the content container (
+ * {@link #getContent()}) instead of in the actual UI.
+ */
@Override
public void replaceComponent(Component oldComponent, Component newComponent) {
- throw new UnsupportedOperationException();
+ getContent().replaceComponent(oldComponent, newComponent);
}
/**
diff --git a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java b/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java
index 405d3d1931..82b9944371 100644
--- a/server/tests/src/com/vaadin/tests/server/component/root/CustomUIClassLoader.java
+++ b/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java
@@ -1,4 +1,4 @@
-package com.vaadin.tests.server.component.root;
+package com.vaadin.tests.server.component.ui;
import java.util.ArrayList;
import java.util.List;
diff --git a/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java b/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java
new file mode 100644
index 0000000000..1b07321605
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java
@@ -0,0 +1,65 @@
+package com.vaadin.tests.server.component.ui;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.UI;
+
+public class UIAddRemoveComponents {
+
+ private static class TestUI extends UI {
+ @Override
+ protected void init(VaadinRequest request) {
+ }
+ }
+
+ @Test
+ public void addComponent() {
+ UI ui = new TestUI();
+ Component c = new Label("abc");
+
+ ui.addComponent(c);
+
+ assertSame(c, ui.iterator().next());
+ assertSame(c, ui.getContent().iterator().next());
+ assertEquals(1, ui.getComponentCount());
+ assertEquals(1, ui.getContent().getComponentCount());
+ }
+
+ @Test
+ public void removeComponent() {
+ UI ui = new TestUI();
+ Component c = new Label("abc");
+
+ ui.addComponent(c);
+
+ ui.removeComponent(c);
+
+ assertFalse(ui.iterator().hasNext());
+ assertFalse(ui.getContent().iterator().hasNext());
+ assertEquals(0, ui.getComponentCount());
+ assertEquals(0, ui.getContent().getComponentCount());
+ }
+
+ @Test
+ public void replaceComponent() {
+ UI ui = new TestUI();
+ Component c = new Label("abc");
+ Component d = new Label("def");
+
+ ui.addComponent(c);
+
+ ui.replaceComponent(c, d);
+
+ assertSame(d, ui.iterator().next());
+ assertSame(d, ui.getContent().iterator().next());
+ assertEquals(1, ui.getComponentCount());
+ assertEquals(1, ui.getContent().getComponentCount());
+ }
+}