summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-11-10 17:50:59 +0200
committerLeif Åstrand <leif@vaadin.com>2011-11-10 17:50:59 +0200
commit57177879ed566c30bbea312f1a088e0d3029a602 (patch)
treee58883dd9529d08bd46f06df67660c0365597340 /src/com
parentcc56362a39d9f31224fb88cead11de38155ce4ea (diff)
downloadvaadin-framework-57177879ed566c30bbea312f1a088e0d3029a602.tar.gz
vaadin-framework-57177879ed566c30bbea312f1a088e0d3029a602.zip
Pass around rootId instead of windowName and use it to find the Root
Diffstat (limited to 'src/com')
-rw-r--r--src/com/vaadin/Application.java45
-rw-r--r--src/com/vaadin/RootTestApplication.java15
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java14
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConnection.java26
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VView.java4
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java14
6 files changed, 63 insertions, 55 deletions
diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java
index 54846c0653..336635ce3f 100644
--- a/src/com/vaadin/Application.java
+++ b/src/com/vaadin/Application.java
@@ -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;
+ }
}
diff --git a/src/com/vaadin/RootTestApplication.java b/src/com/vaadin/RootTestApplication.java
index b4290d8223..714e09f1c2 100644
--- a/src/com/vaadin/RootTestApplication.java
+++ b/src/com/vaadin/RootTestApplication.java
@@ -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;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
index 11ee12c552..a9750e3626 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
@@ -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;
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index 5e0f420d49..9297c4c323 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -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;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VView.java b/src/com/vaadin/terminal/gwt/client/ui/VView.java
index af87610944..049fb2f323 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VView.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VView.java
@@ -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()) {
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index 42f2658a40..469d82e53c 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -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, ");
}