From 4291447dede525a31c38629254499b7b93812be3 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Thu, 22 Dec 2011 16:40:18 +0200 Subject: [PATCH] Root preservation should now work, even with @EagerInit etc. Also if turned on in Root constructor or init(). Limitation: can not preserve roots that are already shown when preservation is turned on (this could be fixed in the future). --- src/com/vaadin/Application.java | 48 +++++++++++++++++---------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java index 9d38c72dcd..83084f4213 100644 --- a/src/com/vaadin/Application.java +++ b/src/com/vaadin/Application.java @@ -2227,25 +2227,22 @@ public class Application implements Terminal.ErrorListener, Serializable { root = roots.get(rootId); - boolean preserveRoot = isRootPreserved(); - - if (root == null && preserveRoot) { + if (root == null && isRootPreserved()) { // Check for a known root - if (retainOnRefreshRoots.isEmpty()) { - return null; - } - - Integer retainedRootId; - if (!hasBrowserDetails) { - throw new RootRequiresMoreInformationException(); - } else { - String windowName = browserDetails.getWindowName(); - retainedRootId = retainOnRefreshRoots.get(windowName); - } + if (!retainOnRefreshRoots.isEmpty()) { + + Integer retainedRootId; + if (!hasBrowserDetails) { + throw new RootRequiresMoreInformationException(); + } else { + String windowName = browserDetails.getWindowName(); + retainedRootId = retainOnRefreshRoots.get(windowName); + } - if (retainedRootId != null) { - rootId = retainedRootId; - root = roots.get(rootId); + if (retainedRootId != null) { + rootId = retainedRootId; + root = roots.get(rootId); + } } } @@ -2269,22 +2266,24 @@ public class Application implements Terminal.ErrorListener, Serializable { } if (!initedRoots.contains(rootId)) { - boolean initRequiresBrowserDetails = preserveRoot + boolean initRequiresBrowserDetails = isRootPreserved() || !root.getClass() .isAnnotationPresent(EagerInit.class); if (initRequiresBrowserDetails && !hasBrowserDetails) { pendingRoots.put(rootId, new PendingRootRequest(request)); } else { - if (preserveRoot) { + root.doInit(request); + + // Remember that this root has been initialized + initedRoots.add(rootId); + + // init() might turn on preserve so do this afterwards + if (isRootPreserved()) { // Remember this root String windowName = request.getBrowserDetails() .getWindowName(); retainOnRefreshRoots.put(windowName, rootId); } - root.doInit(request); - - // Remember that this root has been initialized - initedRoots.add(rootId); } } } // end synchronized block @@ -2327,6 +2326,9 @@ public class Application implements Terminal.ErrorListener, Serializable { */ public void setRootPreserved(boolean rootPreserved) { this.rootPreserved = rootPreserved; + if (!rootPreserved) { + retainOnRefreshRoots.clear(); + } } /** -- 2.39.5