diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-11-01 16:55:28 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-11-01 16:55:28 +0200 |
commit | 45c7d559f791060be0642b9b7c447107c07f2232 (patch) | |
tree | 30dad9264d5c8cc06b29bc18f409170b569b4192 /server | |
parent | 942d1951c0345a93dacd0c3bd91bb32ac00505f2 (diff) | |
download | vaadin-framework-45c7d559f791060be0642b9b7c447107c07f2232.tar.gz vaadin-framework-45c7d559f791060be0642b9b7c447107c07f2232.zip |
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
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/server/AbstractCommunicationManager.java | 21 | ||||
-rw-r--r-- | server/src/com/vaadin/server/Page.java | 4 |
2 files changed, 22 insertions, 3 deletions
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() @@ -2547,6 +2549,23 @@ public abstract class AbstractCommunicationManager implements Serializable { } /** + * 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) { |