diff options
-rw-r--r-- | server/src/com/vaadin/server/VaadinServiceSession.java | 5 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/UI.java | 3 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/TestUICleanup.java | 48 |
3 files changed, 53 insertions, 3 deletions
diff --git a/server/src/com/vaadin/server/VaadinServiceSession.java b/server/src/com/vaadin/server/VaadinServiceSession.java index de5accbfd0..92c06cdf46 100644 --- a/server/src/com/vaadin/server/VaadinServiceSession.java +++ b/server/src/com/vaadin/server/VaadinServiceSession.java @@ -742,7 +742,12 @@ public class VaadinServiceSession implements HttpSessionBindingListener, Integer id = Integer.valueOf(ui.getUIId()); uIs.remove(id); retainOnRefreshUIs.values().remove(id); + + UI current = UI.getCurrent(); + UI.setCurrent(ui); ui.fireCleanupEvent(); + ui.setSession(null); + UI.setCurrent(current); } /** diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index d57d38b371..c7627f71db 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -634,10 +634,7 @@ public abstract class UI extends AbstractComponentContainer implements * For internal use only. */ public void fireCleanupEvent() { - UI current = UI.getCurrent(); - UI.setCurrent(this); fireEvent(new CleanupEvent(this)); - UI.setCurrent(current); } @Override diff --git a/server/tests/src/com/vaadin/tests/server/TestUICleanup.java b/server/tests/src/com/vaadin/tests/server/TestUICleanup.java new file mode 100644 index 0000000000..83d6838bfe --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/TestUICleanup.java @@ -0,0 +1,48 @@ +package com.vaadin.tests.server; + +import org.easymock.EasyMock; +import org.junit.Test; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinService; +import com.vaadin.server.VaadinServiceSession; +import com.vaadin.ui.UI; +import com.vaadin.ui.UI.CleanupEvent; +import com.vaadin.ui.UI.CleanupListener; + +public class TestUICleanup { + + @Test + public void uiDetach() { + VaadinService service = EasyMock.createMock(VaadinService.class); + + UI ui = EasyMock.createMock(UI.class); + ui.setSession(null); + ui.detach(); + ui.fireCleanupEvent(); + EasyMock.expect(ui.getUIId()).andReturn(1); + + EasyMock.replay(service, ui); + + VaadinServiceSession session = new VaadinServiceSession(service); + + session.cleanupUI(ui); + } + + @Test + public void uiCleanupListeners() { + CleanupListener listener = EasyMock.createMock(CleanupListener.class); + listener.cleanup(EasyMock.anyObject(CleanupEvent.class)); + + EasyMock.replay(listener); + + UI ui = new UI() { + @Override + protected void init(VaadinRequest request) { + } + }; + + ui.addCleanupListener(listener); + ui.fireCleanupEvent(); + } +} |