]> source.dussan.org Git - vaadin-framework.git/commitdiff
Pass around rootId instead of windowName and use it to find the Root
authorLeif Åstrand <leif@vaadin.com>
Thu, 10 Nov 2011 15:50:59 +0000 (17:50 +0200)
committerLeif Åstrand <leif@vaadin.com>
Thu, 10 Nov 2011 15:50:59 +0000 (17:50 +0200)
src/com/vaadin/Application.java
src/com/vaadin/RootTestApplication.java
src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/ui/VView.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java

index 54846c06539ba61cf0b78306524b02a878d100e2..336635ce3f7c4ce8d44b3ec85bec5405e9c01478 100644 (file)
@@ -14,9 +14,12 @@ import java.util.Collections;
 import java.util.Enumeration;
 import java.util.EventListener;
 import java.util.EventObject;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.Locale;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -30,6 +33,7 @@ import com.vaadin.terminal.Terminal;
 import com.vaadin.terminal.VariableOwner;
 import com.vaadin.terminal.WrappedRequest;
 import com.vaadin.terminal.WrappedResponse;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent;
 import com.vaadin.terminal.gwt.server.WebApplicationContext;
 import com.vaadin.ui.AbstractComponent;
@@ -160,6 +164,9 @@ public abstract class Application implements Terminal.ErrorListener,
 
     private LinkedList<RequestHandler> requestHandlers = new LinkedList<RequestHandler>();
 
+    private int nextRootId = 0;
+    private Map<Integer, Root> roots = new HashMap<Integer, Root>();
+
     /**
      * Gets the user of the application.
      * 
@@ -1443,7 +1450,34 @@ public abstract class Application implements Terminal.ErrorListener,
 
     }
 
-    public abstract Root getRoot(WrappedRequest request);
+    public Root getRoot(WrappedRequest request) {
+        String rootIdString = request
+                .getParameter(ApplicationConnection.ROOT_ID_PARAMETER);
+        Root root;
+        synchronized (this) {
+            // getRoot might be called from outside the synchronized UIDL
+            // handling
+            if (rootIdString == null) {
+                // TODO What if getRoot is called again for this request?
+
+                // TODO implement support for throwing exception if more
+                // information is required to create a root
+                root = createRoot(request);
+                root.setApplication(this);
+
+                // TODO implement lazy init of root if indicated by annotation
+                root.init(request);
+                roots.put(Integer.valueOf(nextRootId++), root);
+            } else {
+                Integer rootId = new Integer(rootIdString);
+                root = roots.get(rootId);
+            }
+        }
+
+        return root;
+    }
+
+    protected abstract Root createRoot(WrappedRequest request);
 
     public boolean handleRequest(WrappedRequest request,
             WrappedResponse response) throws IOException {
@@ -1482,4 +1516,13 @@ public abstract class Application implements Terminal.ErrorListener,
     public static void setCurrentApplication(Application application) {
         currentApplication.set(application);
     }
+
+    public int getRootId(Root root) {
+        for (Entry<Integer, Root> entry : roots.entrySet()) {
+            if (entry.getValue() == root) {
+                return entry.getKey().intValue();
+            }
+        }
+        return -1;
+    }
 }
index b4290d822314567fb451e534505c78e6db0b86d7..714e09f1c23164e29ec13c935d1b14d941129145 100644 (file)
@@ -90,8 +90,6 @@ public class RootTestApplication extends Application {
         }
     }
 
-    private Root root;
-
     @Override
     public void init() {
         addRequestHandler(new RequestHandler() {
@@ -115,16 +113,9 @@ public class RootTestApplication extends Application {
     }
 
     @Override
-    public Root getRoot(WrappedRequest request) {
-        if (root == null) {
-            String rootText = request.getParameter("rootText");
-            root = new Root(new MyRootLayout(rootText));
-
-            // TODO Should be done by Application during init
-            root.setApplication(this);
-            root.init(request);
-        }
-
+    protected Root createRoot(WrappedRequest request) {
+        String rootText = request.getParameter("rootText");
+        Root root = new Root(new MyRootLayout(rootText));
         return root;
     }
 
index 11ee12c5529c72bd91242462ec6f9f27ce19f886..a9750e3626bdd9480b900ea7c61a501a668de480 100644 (file)
@@ -40,7 +40,7 @@ public class ApplicationConfiguration implements EntryPoint {
     private String themeUri;
     private String appUri;
     private JavaScriptObject versionInfo;
-    private String windowName;
+    private int rootId;
     private boolean standalone;
     private String communicationErrorCaption;
     private String communicationErrorMessage;
@@ -105,12 +105,8 @@ public class ApplicationConfiguration implements EntryPoint {
         return standalone;
     }
 
-    public void setInitialWindowName(String name) {
-        windowName = name;
-    }
-
-    public String getInitialWindowName() {
-        return windowName;
+    public int getRootId() {
+        return rootId;
     }
 
     public JavaScriptObject getVersionInfoJSObject() {
@@ -157,8 +153,8 @@ public class ApplicationConfiguration implements EntryPoint {
             }
             this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::appUri = uri;
             this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::themeUri = jsobj.themeUri;
-            if(jsobj.windowName) {
-                this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::windowName = jsobj.windowName;
+            if(jsobj.rootId) {
+                this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::rootId = jsobj.rootId;
             }
             if('useDebugIdInDom' in jsobj && typeof(jsobj.useDebugIdInDom) == "boolean") {
                 this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::useDebugIdInDom = jsobj.useDebugIdInDom;
index 5e0f420d49678fe4ca57dd959c32b55d62ac1df2..9297c4c323b07900499e44bd2312347f22be4160 100644 (file)
@@ -83,6 +83,8 @@ public class ApplicationConnection {
 
     public static final String UIDL_SECURITY_TOKEN_ID = "Vaadin-Security-Key";
 
+    public static final String ROOT_ID_PARAMETER = "rootId";
+
     /**
      * @deprecated use UIDL_SECURITY_TOKEN_ID instead
      */
@@ -163,7 +165,6 @@ public class ApplicationConnection {
 
         this.widgetSet = widgetSet;
         configuration = cnf;
-        windowName = configuration.getInitialWindowName();
 
         ComponentLocator componentLocator = new ComponentLocator(this);
 
@@ -432,9 +433,8 @@ public class ApplicationConnection {
         if (extraParams != null && extraParams.length() > 0) {
             uri = addGetParameters(uri, extraParams);
         }
-        if (windowName != null && windowName.length() > 0) {
-            uri = addGetParameters(uri, "windowName=" + windowName);
-        }
+        uri = addGetParameters(uri,
+                ROOT_ID_PARAMETER + "=" + configuration.getRootId());
 
         doUidlRequest(uri, payload, forceSync);
 
@@ -2364,24 +2364,6 @@ public class ApplicationConnection {
         layoutTimer.schedule(500);
     }
 
-    private String windowName = null;
-
-    /**
-     * Reset the name of the current browser-window. This should reflect the
-     * window-name used in the server, but might be different from the
-     * window-object target-name on client.
-     * 
-     * @param stringAttribute
-     *            New name for the window.
-     */
-    public void setWindowName(String newName) {
-        windowName = newName;
-    }
-
-    protected String getWindowName() {
-        return windowName;
-    }
-
     protected String getUidlSecurityKey() {
         return uidlSecurityKey;
     }
index af87610944c7ba83ee54f8033ded7ed2d7c445d4..049fb2f323da99e42183f8cb2ba19aac8dc0059c 100644 (file)
@@ -213,10 +213,6 @@ public class VView extends SimplePanel implements Container, ResizeHandler,
                     + uidl.getStringAttribute("style"));
         }
 
-        if (uidl.hasAttribute("name")) {
-            client.setWindowName(uidl.getStringAttribute("name"));
-        }
-
         clickEventHandler.handleEventHandlerRegistration(client);
 
         if (!isEmbedded()) {
index 42f2658a40cb6b06c58c292a0672504c0880bac7..469d82e53c82f458e9ad58601cd9c5134f0e6351 100644 (file)
@@ -1647,7 +1647,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         appId = appId + "-" + hashCode;
 
         writeAjaxPageHtmlVaadinScripts(themeName, application, page, appUrl,
-                themeUri, appId, request);
+                themeUri, appId, request, application.getRootId(root));
 
         /*- Add classnames;
          *      .v-app
@@ -1768,6 +1768,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * @param themeUri
      * @param appId
      * @param request
+     * @param rootId
      * @throws ServletException
      * @throws IOException
      */
@@ -1775,8 +1776,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
             // Window window,
             String themeName, Application application,
             final BufferedWriter page, String appUrl, String themeUri,
-            String appId, HttpServletRequest request) throws ServletException,
-            IOException {
+            String appId, HttpServletRequest request, int rootId)
+            throws ServletException, IOException {
 
         // request widgetset takes precedence (e.g portlet include)
         String requestWidgetset = (String) request
@@ -1834,10 +1835,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         page.write("vaadin.vaadinConfigurations[\"" + appId + "\"] = {");
         page.write("appUri:'" + appUrl + "', ");
 
-        // if (window != application.getMainWindow()) {
-        // page.write("windowName: \""
-        // + JsonPaintTarget.escapeJSON(window.getName()) + "\", ");
-        // }
+        page.write(ApplicationConnection.ROOT_ID_PARAMETER + ": " + rootId
+                + ", ");
+
         if (isStandalone()) {
             page.write("standalone: true, ");
         }