]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update location when initialized UI is opened again (#10044) 94/194/1
authorLeif Åstrand <leif@vaadin.com>
Thu, 1 Nov 2012 14:55:28 +0000 (16:55 +0200)
committerLeif Åstrand <leif@vaadin.com>
Thu, 1 Nov 2012 14:55:28 +0000 (16:55 +0200)
* Also fix Page.updateLocation to avoid NPE if fragment changes from
null to null

Change-Id: I03f3883c2653eaf438ccdfc313078fbe8fe898bc

server/src/com/vaadin/server/AbstractCommunicationManager.java
server/src/com/vaadin/server/Page.java
uitest/src/com/vaadin/tests/application/RefreshFragmentChange.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java

index 43a9ced608a70fe95f8ffc97bf3f8b0be04574b4..c3a62132656075d559f2109e93d6c421aec191c6 100644 (file)
@@ -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.
index 1f4ff040acbea030019a7d039db4b098baf8378f..ab8c591b133c388cc76b81da63c3c2db4f567f2f 100644 (file)
@@ -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) {
diff --git a/uitest/src/com/vaadin/tests/application/RefreshFragmentChange.html b/uitest/src/com/vaadin/tests/application/RefreshFragmentChange.html
new file mode 100644 (file)
index 0000000..147e67f
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.application.RefreshStatePreserve?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::PID_SLog_row_0</td>
+       <td>1. Initial fragment: null</td>
+</tr>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.application.RefreshStatePreserve#asdf</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::PID_SLog_row_0</td>
+       <td>2. Fragment changed to asdf</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
index c99e384f8139d72b1292308f02367a24ea2d01c6..f4d7f2a4e42e6eaf86c77d908eff4a770b98f6f1 100644 (file)
@@ -1,18 +1,32 @@
 package com.vaadin.tests.application;
 
 import com.vaadin.annotations.PreserveOnRefresh;
+import com.vaadin.server.Page.FragmentChangedEvent;
+import com.vaadin.server.Page.FragmentChangedListener;
 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 RefreshStatePreserve extends AbstractTestUI {
 
+    private Log log = new Log(5);
+
     @Override
     protected void setup(VaadinRequest request) {
         // Internal parameter sent by vaadinBootstrap.js,
         addComponent(new Label("window.name: " + request.getParameter("wn")));
         addComponent(new Label("UI id: " + getUIId()));
+        addComponent(log);
+
+        log.log("Initial fragment: " + getPage().getFragment());
+        getPage().addFragmentChangedListener(new FragmentChangedListener() {
+            @Override
+            public void fragmentChanged(FragmentChangedEvent event) {
+                log.log("Fragment changed to " + event.getFragment());
+            }
+        });
     }
 
     @Override
@@ -24,4 +38,4 @@ public class RefreshStatePreserve extends AbstractTestUI {
     protected Integer getTicketNumber() {
         return Integer.valueOf(8068);
     }
-}
+}
\ No newline at end of file