From 104e472d21e92c3023abc4cfe96e67861424927c Mon Sep 17 00:00:00 2001 From: Joonas Lehtinen Date: Fri, 28 Jun 2013 18:19:47 +0300 Subject: [PATCH] Fixes @PreserveOnRefresh losing page title on refresh #11054 Moves Page title to PageState instead of using RPC for changing the title on Page.setTitle(). Change-Id: I8e5ab2064c04235503fb2531f4cdbb108530ac7e --- .../com/vaadin/client/ui/ui/UIConnector.java | 9 ++--- server/src/com/vaadin/server/Page.java | 2 +- .../vaadin/shared/ui/ui/PageClientRpc.java | 2 -- .../com/vaadin/shared/ui/ui/PageState.java | 5 +++ .../RefreshStatePreserveTitle.html | 36 +++++++++++++++++++ .../RefreshStatePreserveTitle.java | 30 ++++++++++++++++ 6 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.html create mode 100644 uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.java diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 45b0a7ab9d..460cde5522 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -100,10 +100,6 @@ public class UIConnector extends AbstractSingleComponentContainerConnector protected void init() { super.init(); registerRpc(PageClientRpc.class, new PageClientRpc() { - @Override - public void setTitle(String title) { - com.google.gwt.user.client.Window.setTitle(title); - } @Override public void reload() { @@ -644,6 +640,11 @@ public class UIConnector extends AbstractSingleComponentContainerConnector configurePolling(); } + if (stateChangeEvent.hasPropertyChanged("title")) { + com.google.gwt.user.client.Window + .setTitle(getState().pageState.title); + } + if (stateChangeEvent.hasPropertyChanged("pushConfiguration")) { getConnection().setPushEnabled( getState().pushConfiguration.mode.isEnabled()); diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 4dd7d34e38..4d7d2c10c5 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -1079,7 +1079,7 @@ public class Page implements Serializable { * the new page title to set */ public void setTitle(String title) { - uI.getRpcProxy(PageClientRpc.class).setTitle(title); + getState(true).title = title; } /** diff --git a/shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java b/shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java index eb847bacd0..76a3fbfdb6 100644 --- a/shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java +++ b/shared/src/com/vaadin/shared/ui/ui/PageClientRpc.java @@ -20,8 +20,6 @@ import com.vaadin.shared.communication.ClientRpc; public interface PageClientRpc extends ClientRpc { - public void setTitle(String title); - public void reload(); } diff --git a/shared/src/com/vaadin/shared/ui/ui/PageState.java b/shared/src/com/vaadin/shared/ui/ui/PageState.java index 0b51eb4bba..ded73d16d5 100644 --- a/shared/src/com/vaadin/shared/ui/ui/PageState.java +++ b/shared/src/com/vaadin/shared/ui/ui/PageState.java @@ -30,4 +30,9 @@ public class PageState implements Serializable { * True if the page has browser window resize listeners. */ public boolean hasResizeListeners = false; + + /** + * Non-null if the title is set. + */ + public String title = null; } \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.html b/uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.html new file mode 100644 index 0000000000..f366054f45 --- /dev/null +++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.html @@ -0,0 +1,36 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.application.RefreshStatePreserveTitle?restartApplication
assertTitleTEST
open/run/com.vaadin.tests.application.RefreshStatePreserveTitle
assertTitleTEST
+ + diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.java b/uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.java new file mode 100644 index 0000000000..88b3a9b9f4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserveTitle.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.application; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.Label; + +@PreserveOnRefresh +public class RefreshStatePreserveTitle extends AbstractTestUI { + + private Log log = new Log(5); + + @Override + protected void setup(VaadinRequest request) { + getPage().setTitle("TEST"); + addComponent(new Label( + "Refresh the page and observe that window title 'TEST' is lost.")); + } + + @Override + protected String getTestDescription() { + return "Refreshing the browser window should preserve the window title"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(11054); + } +} \ No newline at end of file -- 2.39.5