@@ -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; | |||
} | |||
} |
@@ -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; | |||
} | |||
@@ -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; |
@@ -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; | |||
} |
@@ -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()) { |
@@ -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, "); | |||
} |