From 45c7d559f791060be0642b9b7c447107c07f2232 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 1 Nov 2012 16:55:28 +0200 Subject: Update location when initialized UI is opened again (#10044) * Also fix Page.updateLocation to avoid NPE if fragment changes from null to null Change-Id: I03f3883c2653eaf438ccdfc313078fbe8fe898bc --- .../vaadin/server/AbstractCommunicationManager.java | 21 ++++++++++++++++++++- server/src/com/vaadin/server/Page.java | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 43a9ced608..c3a6213265 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -61,6 +61,7 @@ import org.json.JSONException; import org.json.JSONObject; import com.vaadin.annotations.JavaScript; +import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.annotations.StyleSheet; import com.vaadin.server.ComponentSizeValidator.InvalidLayout; import com.vaadin.server.RpcManager.RpcInvocationException; @@ -2467,7 +2468,7 @@ public abstract class AbstractCommunicationManager implements Serializable { UI existingUi = legacyProvider .getExistingUI(classSelectionEvent); if (existingUi != null) { - UI.setCurrent(existingUi); + reinitUI(existingUi, request); return existingUi; } } @@ -2498,6 +2499,7 @@ public abstract class AbstractCommunicationManager implements Serializable { if (retainedUIId != null) { UI retainedUI = session.getUIById(retainedUIId.intValue()); if (uiClass.isInstance(retainedUI)) { + reinitUI(retainedUI, request); return retainedUI; } else { getLogger() @@ -2546,6 +2548,23 @@ public abstract class AbstractCommunicationManager implements Serializable { return ui; } + /** + * Updates a UI that has already been initialized but is now loaded again, + * e.g. because of {@link PreserveOnRefresh}. + * + * @param ui + * @param request + */ + private void reinitUI(UI ui, VaadinRequest request) { + UI.setCurrent(ui); + + // Fire fragment change if the fragment has changed + String location = request.getParameter("loc"); + if (location != null) { + ui.getPage().updateLocation(location); + } + } + /** * Generates the initial UIDL message that can e.g. be included in a html * page to avoid a separate round trip just for getting the UIDL. diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 1f4ff040ac..ab8c591b13 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -657,8 +657,8 @@ public class Page implements Serializable { String oldFragment = this.location.getFragment(); this.location = new URI(location); String newFragment = this.location.getFragment(); - if (newFragment == null && oldFragment != null - || !newFragment.equals(oldFragment)) { + if (newFragment == null ? oldFragment != null : !newFragment + .equals(oldFragment)) { fireEvent(new FragmentChangedEvent(this, newFragment)); } } catch (URISyntaxException e) { -- cgit v1.2.3