summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-11-24 15:33:22 +0200
committerLeif Åstrand <leif@vaadin.com>2011-11-24 15:33:22 +0200
commit0b4297ddd24758e2a7235c5afdbcc0c94613c298 (patch)
tree7a58bcd4595d158dbd50b3ec85e49853dae8a8b0
parent181b76b3a041d061e0a8fff3fbfaf7f0e64da2da (diff)
downloadvaadin-framework-0b4297ddd24758e2a7235c5afdbcc0c94613c298.tar.gz
vaadin-framework-0b4297ddd24758e2a7235c5afdbcc0c94613c298.zip
Introduce vaadinBootstrap.js and use it to init the widgetset
-rw-r--r--WebContent/VAADIN/vaadinBootstrap.js115
-rw-r--r--src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml3
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java264
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConnection.java13
-rw-r--r--src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java186
5 files changed, 335 insertions, 246 deletions
diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js
new file mode 100644
index 0000000000..917aa2aa4a
--- /dev/null
+++ b/WebContent/VAADIN/vaadinBootstrap.js
@@ -0,0 +1,115 @@
+(function() {
+ var defaults;
+ var apps = {};
+ var themesLoaded = {};
+ var widgetsetsRequested = {}
+ var widgetsetApps = {};
+
+
+ var log = function() {
+ if (console && console.log) {
+ console.log(arguments);
+ }
+ }
+
+ var loadTheme = function(url) {
+ log("loadTheme", url);
+ if(!themesLoaded[url]) {
+ var stylesheet = document.createElement('link');
+ stylesheet.setAttribute('rel', 'stylesheet');
+ stylesheet.setAttribute('type', 'text/css');
+ stylesheet.setAttribute('href', url + "/styles.css");
+ document.getElementsByTagName('head')[0].appendChild(stylesheet);
+ themesLoaded[url] = true;
+ }
+ }
+
+ var isWidgetsetLoaded = function(widgetset) {
+ var className = widgetset.replace(/\./g, "_");
+ return (typeof window[className]) != "undefined";
+ }
+
+ var loadWidgetset = function(basePath, widgetset) {
+ if (widgetsetsRequested[widgetset]) {
+ //TODO Tell the widgetset to load another application
+ return;
+ }
+ log("load widgetset", basePath, widgetset)
+ setTimeout(function() {
+ if (!isWidgetsetLoaded(widgetset)) {
+ alert("Failed to load the widgetset: " + url);
+ }
+ }, 15000);
+
+ var url = basePath + widgetset + "/" + widgetset + ".nocache.js?" + new Date().getTime();
+
+ //document.write("<script type='text/javascript' src='"+url+"'></script>");
+
+ var scriptTag = document.createElement('script');
+ scriptTag.setAttribute('type', 'text/javascript');
+ scriptTag.setAttribute('src', url);
+ document.getElementsByTagName('head')[0].appendChild(scriptTag);
+
+ widgetsetsRequested[widgetset] = true;
+ }
+
+ window.vaadin = window.vaadin || {
+ setDefaults: function(d) {
+ if (defaults) {
+ throw "Defaults already defined";
+ }
+ log("Got defaults", defaults)
+ defaults = d;
+ },
+ initApplication: function(appId, config) {
+ if (apps[appId]) {
+ throw "Application " + appId + " already initialized";
+ }
+ log("init application", appId, config);
+ var getConfig = function(name) {
+ var value = config[name];
+ if (value === undefined) {
+ value = defaults[name];
+ }
+ return value;
+ }
+
+ var themeUri = getConfig('themeUri');
+ if (themeUri) {
+ loadTheme(themeUri);
+ }
+
+ var widgetsetBase = getConfig('widgetsetBase');
+ var widgetset = getConfig('widgetset');
+ if (widgetset && widgetsetBase) {
+ loadWidgetset(widgetsetBase, widgetset);
+ if (widgetsetApps[widgetset]) {
+ widgetsetApps[widgetset].push(appId);
+ } else {
+ widgetsetApps[widgetset] = [appId];
+ }
+ }
+
+ //Export public data
+ var app = {
+ 'getConfig': getConfig
+ };
+ apps[appId] = app;
+
+ return app;
+ },
+ getApp: function(appId) {
+ var app = apps[appId];
+ return app;
+ },
+ popWidgetsetApp: function(widgetset) {
+ if (widgetsetApps[widgetset]) {
+ return widgetsetApps[widgetset].pop();
+ } else {
+ return null;
+ }
+ }
+ };
+
+ log('Vaadin bootstrap loaded');
+})(); \ No newline at end of file
diff --git a/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml b/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml
index bdbcc75222..9cf2a828db 100644
--- a/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml
+++ b/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml
@@ -69,6 +69,9 @@
</replace-with>
<entry-point class="com.vaadin.terminal.gwt.client.ApplicationConfiguration" />
+
+ <!-- Use the new cross site linker to get a nocache.js without document.write -->
+ <add-linker name="xsiframe" />
</module>
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
index a9750e3626..854deb6e84 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
@@ -5,7 +5,6 @@ package com.vaadin.terminal.gwt.client;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -20,6 +19,84 @@ import com.vaadin.terminal.gwt.client.ui.VUnknownComponent;
public class ApplicationConfiguration implements EntryPoint {
+ private static class JsoConfiguration extends JavaScriptObject {
+ protected JsoConfiguration() {
+ // JSO Constructor
+ }
+
+ private native String getConfigString(String name)
+ /*-{
+ var value = this.getConfig(name);
+ if (!value) {
+ return null;
+ } else {
+ return value +"";
+ }
+ }-*/;
+
+ private native Boolean getConfigBoolean(String name)
+ /*-{
+ var value = this.getConfig(name);
+ if (value === null || value === undefined) {
+ return null;
+ } else {
+ return @java.lang.Boolean::valueOf(Z)(value);
+ }
+ }-*/;
+
+ private native Integer getConfigInteger(String name)
+ /*-{
+ var value = this.getConfig(name);
+ if (value === null || value === undefined) {
+ return null;
+ } else {
+ return @java.lang.Integer::valueOf(I)(value);
+ }
+ }-*/;
+
+ private native ErrorMessage getConfigError(String name)
+ /*-{
+ return this.getConfig(name);
+ }-*/;
+
+ private native JavaScriptObject getVersionInfoJSObject()
+ /*-{
+ return this.getConfig("versionInfo");
+ }-*/;
+
+ private native String getVaadinVersion()
+ /*-{
+ return this.getConfig("versionInfo").vaadinVersion;
+ }-*/;
+
+ private native String getApplicationVersion()
+ /*-{
+ return this.getConfig("versionInfo").applicationVersion;
+ }-*/;
+ }
+
+ public static final class ErrorMessage extends JavaScriptObject {
+
+ protected ErrorMessage() {
+ // JSO constructor
+ }
+
+ public final native String getCaption()
+ /*-{
+ return this.caption;
+ }-*/;
+
+ public final native String getMessage()
+ /*-{
+ return this.message;
+ }-*/;
+
+ public final native String getUrl()
+ /*-{
+ return this.url;
+ }-*/;
+ }
+
/**
* Builds number. For example 0-custom_tag in 5.0.0-custom_tag.
*/
@@ -39,16 +116,10 @@ public class ApplicationConfiguration implements EntryPoint {
private String id;
private String themeUri;
private String appUri;
- private JavaScriptObject versionInfo;
private int rootId;
private boolean standalone;
- private String communicationErrorCaption;
- private String communicationErrorMessage;
- private String communicationErrorUrl;
- private String authorizationErrorCaption;
- private String authorizationErrorMessage;
- private String authorizationErrorUrl;
- private String requiredWidgetset;
+ private ErrorMessage communicationError;
+ private ErrorMessage authorizationError;
private boolean useDebugIdInDom = true;
private boolean usePortletURLs = false;
private String portletUidlURLBase;
@@ -64,7 +135,6 @@ public class ApplicationConfiguration implements EntryPoint {
private static int widgetsLoading;
- private static ArrayList<ApplicationConnection> unstartedApplications = new ArrayList<ApplicationConnection>();
private static ArrayList<ApplicationConnection> runningApplications = new ArrayList<ApplicationConnection>();
public boolean usePortletURLs() {
@@ -110,131 +180,41 @@ public class ApplicationConfiguration implements EntryPoint {
}
public JavaScriptObject getVersionInfoJSObject() {
- return versionInfo;
+ return getJsoConfiguration(id).getVersionInfoJSObject();
}
- public String getCommunicationErrorCaption() {
- return communicationErrorCaption;
+ public ErrorMessage getCommunicationError() {
+ return communicationError;
}
- public String getCommunicationErrorMessage() {
- return communicationErrorMessage;
+ public ErrorMessage getAuthorizationError() {
+ return authorizationError;
}
- public String getCommunicationErrorUrl() {
- return communicationErrorUrl;
- }
-
- public String getAuthorizationErrorCaption() {
- return authorizationErrorCaption;
- }
-
- public String getAuthorizationErrorMessage() {
- return authorizationErrorMessage;
- }
-
- public String getAuthorizationErrorUrl() {
- return authorizationErrorUrl;
- }
-
- public String getRequiredWidgetset() {
- return requiredWidgetset;
- }
-
- private native void loadFromDOM()
- /*-{
-
- var id = this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::id;
- if($wnd.vaadin.vaadinConfigurations && $wnd.vaadin.vaadinConfigurations[id]) {
- var jsobj = $wnd.vaadin.vaadinConfigurations[id];
- var uri = jsobj.appUri;
- if(uri != null && uri[uri.length -1] != "/") {
- uri = uri + "/";
- }
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::appUri = uri;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::themeUri = jsobj.themeUri;
- 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;
- }
- if(jsobj.versionInfo) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo = jsobj.versionInfo;
- }
- if(jsobj.comErrMsg) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorCaption = jsobj.comErrMsg.caption;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorMessage = jsobj.comErrMsg.message;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorUrl = jsobj.comErrMsg.url;
- }
- if(jsobj.authErrMsg) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::authorizationErrorCaption = jsobj.authErrMsg.caption;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::authorizationErrorMessage = jsobj.authErrMsg.message;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::authorizationErrorUrl = jsobj.authErrMsg.url;
- }
- if (jsobj.usePortletURLs) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::usePortletURLs = jsobj.usePortletURLs;
- }
- if (jsobj.portletUidlURLBase) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::portletUidlURLBase = jsobj.portletUidlURLBase;
- }
- if (jsobj.standalone) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::standalone = true;
- }
- if (jsobj.widgetset) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::requiredWidgetset = jsobj.widgetset;
- }
- } else {
- $wnd.alert("Vaadin app failed to initialize: " + this.id);
+ private void loadFromDOM() {
+ JsoConfiguration jsoConfiguration = getJsoConfiguration(id);
+ appUri = jsoConfiguration.getConfigString("appUri");
+ if (appUri != null && !appUri.endsWith("/")) {
+ appUri += '/';
}
+ themeUri = jsoConfiguration.getConfigString("themeUri");
+ rootId = jsoConfiguration.getConfigInteger("rootId").intValue();
- }-*/;
+ // null -> true
+ useDebugIdInDom = jsoConfiguration.getConfigBoolean("useDebugIdInDom") != Boolean.FALSE;
- /**
- * Inits the ApplicationConfiguration by reading the DOM and instantiating
- * ApplicationConnections accordingly. Call {@link #startNextApplication()}
- * to actually start the applications.
- *
- * @param widgetset
- * the widgetset that is running the apps
- */
- public static void initConfigurations() {
-
- ArrayList<String> appIds = new ArrayList<String>();
- loadAppIdListFromDOM(appIds);
-
- for (Iterator<String> it = appIds.iterator(); it.hasNext();) {
- String appId = it.next();
- ApplicationConfiguration appConf = getConfigFromDOM(appId);
- if (canStartApplication(appConf)) {
- ApplicationConnection a = GWT
- .create(ApplicationConnection.class);
- a.init(widgetSet, appConf);
- unstartedApplications.add(a);
- consumeApplication(appId);
- } else {
- VConsole.log("Application "
- + appId
- + " was not started. Provided widgetset did not match with this module.");
- }
- }
+ // null -> false
+ usePortletURLs = jsoConfiguration.getConfigBoolean("usePortletURLs") == Boolean.TRUE;
- }
+ portletUidlURLBase = jsoConfiguration
+ .getConfigString("portletUidlURLBase");
- /**
- * Marks an applicatin with given id to be initialized. Suggesting other
- * modules should not try to start this application anymore.
- *
- * @param appId
- */
- private native static void consumeApplication(String appId)
- /*-{
- $wnd.vaadin.vaadinConfigurations[appId].initialized = true;
- }-*/;
+ // null -> false
+ standalone = jsoConfiguration.getConfigBoolean("standalone") == Boolean.TRUE;
+
+ communicationError = jsoConfiguration.getConfigError("comErrMsg");
+ authorizationError = jsoConfiguration.getConfigError("authErrMsg");
- private static boolean canStartApplication(ApplicationConfiguration appConf) {
- return appConf.getRequiredWidgetset() == null
- || appConf.getRequiredWidgetset().equals(GWT.getModuleName());
}
/**
@@ -246,8 +226,12 @@ public class ApplicationConfiguration implements EntryPoint {
* @return true if an unstarted application was found
*/
public static boolean startNextApplication() {
- if (unstartedApplications.size() > 0) {
- ApplicationConnection a = unstartedApplications.remove(0);
+ String applicationId = getNextUnstartedApplicationId(GWT
+ .getModuleName());
+ if (applicationId != null) {
+ ApplicationConfiguration appConf = getConfigFromDOM(applicationId);
+ ApplicationConnection a = GWT.create(ApplicationConnection.class);
+ a.init(widgetSet, appConf);
a.start();
runningApplications.add(a);
return true;
@@ -261,14 +245,15 @@ public class ApplicationConfiguration implements EntryPoint {
return runningApplications;
}
- private native static void loadAppIdListFromDOM(ArrayList<String> list)
+ private native static String getNextUnstartedApplicationId(
+ String widgetsetName)
+ /*-{
+ return $wnd.vaadin.popWidgetsetApp(widgetsetName);
+ }-*/;
+
+ private native static JsoConfiguration getJsoConfiguration(String appId)
/*-{
- var j;
- for(j in $wnd.vaadin.vaadinConfigurations) {
- if(!$wnd.vaadin.vaadinConfigurations[j].initialized) {
- list.@java.util.Collection::add(Ljava/lang/Object;)(j);
- }
- }
+ return $wnd.vaadin.getApp(appId);
}-*/;
public static ApplicationConfiguration getConfigFromDOM(String appId) {
@@ -278,15 +263,13 @@ public class ApplicationConfiguration implements EntryPoint {
return conf;
}
- public native String getServletVersion()
- /*-{
- return this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo.vaadinVersion;
- }-*/;
+ public String getServletVersion() {
+ return getJsoConfiguration(id).getVaadinVersion();
+ }
- public native String getApplicationVersion()
- /*-{
- return this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo.applicationVersion;
- }-*/;
+ public String getApplicationVersion() {
+ return getJsoConfiguration(id).getApplicationVersion();
+ }
public boolean useDebugIdInDOM() {
return useDebugIdInDom;
@@ -464,7 +447,6 @@ public class ApplicationConfiguration implements EntryPoint {
}
});
- initConfigurations();
startNextApplication();
}
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index 88f562bb92..8f745bba80 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -33,6 +33,7 @@ import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConfiguration.ErrorMessage;
import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
import com.vaadin.terminal.gwt.client.RenderInformation.Size;
import com.vaadin.terminal.gwt.client.ui.Field;
@@ -617,9 +618,9 @@ public class ApplicationConnection {
*/
protected void showCommunicationError(String details) {
VConsole.error("Communication error: " + details);
- showError(details, configuration.getCommunicationErrorCaption(),
- configuration.getCommunicationErrorMessage(),
- configuration.getCommunicationErrorUrl());
+ ErrorMessage communicationError = configuration.getCommunicationError();
+ showError(details, communicationError.getCaption(),
+ communicationError.getMessage(), communicationError.getUrl());
}
/**
@@ -630,9 +631,9 @@ public class ApplicationConnection {
*/
protected void showAuthenticationError(String details) {
VConsole.error("Authentication error: " + details);
- showError(details, configuration.getAuthorizationErrorCaption(),
- configuration.getAuthorizationErrorMessage(),
- configuration.getAuthorizationErrorUrl());
+ ErrorMessage authorizationError = configuration.getAuthorizationError();
+ showError(details, authorizationError.getCaption(),
+ authorizationError.getMessage(), authorizationError.getUrl());
}
/**
diff --git a/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java b/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java
index 75ca37f6eb..3979ab4ff2 100644
--- a/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java
+++ b/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java
@@ -4,9 +4,11 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
import com.vaadin.Application;
+import com.vaadin.external.json.JSONException;
+import com.vaadin.external.json.JSONObject;
import com.vaadin.terminal.RequestHandler;
import com.vaadin.terminal.WrappedRequest;
import com.vaadin.terminal.WrappedResponse;
@@ -23,17 +25,22 @@ public abstract class AjaxPageHandler implements RequestHandler {
Root root = application.getRoot(request);
if (root == null) {
- writeError(response, null);
+ writeError(response, new Throwable("No Root found"));
return true;
}
- writeAjaxPage(request, response, root);
+ try {
+ writeAjaxPage(request, response, root);
+ } catch (JSONException e) {
+ writeError(response, e);
+ }
return true;
}
protected final void writeAjaxPage(WrappedRequest request,
- WrappedResponse response, Root root) throws IOException {
+ WrappedResponse response, Root root) throws IOException,
+ JSONException {
Application application = root.getApplication();
final BufferedWriter page = new BufferedWriter(new OutputStreamWriter(
response.getOutputStream(), "UTF-8"));
@@ -71,6 +78,7 @@ public abstract class AjaxPageHandler implements RequestHandler {
}
appId = appId + "-" + hashCode;
+ // TODO include initial UIDL in the scripts?
writeAjaxPageHtmlVaadinScripts(themeName, page, appUrl, themeUri,
appId, request, root);
@@ -177,129 +185,109 @@ public abstract class AjaxPageHandler implements RequestHandler {
* @param appId
* @param request
* @param rootId
- * @throws ServletException
* @throws IOException
+ * @throws JSONException
*/
protected void writeAjaxPageHtmlVaadinScripts(String themeName,
final BufferedWriter page, String appUrl, String themeUri,
- String appId, WrappedRequest request, Root root) throws IOException {
+ String appId, WrappedRequest request, Root root)
+ throws IOException, JSONException {
Application application = root.getApplication();
- String widgetset = application.getWidgetsetForRoot(root);
- if (widgetset == null) {
- widgetset = getApplicationOrSystemProperty(request,
- AbstractApplicationServlet.PARAMETER_WIDGETSET,
- AbstractApplicationServlet.DEFAULT_WIDGETSET);
- }
- String widgetsetBasePath = request.getStaticFileLocation();
-
- widgetset = AbstractApplicationServlet.stripSpecialChars(widgetset);
+ String staticFileLocation = request.getStaticFileLocation();
- final String widgetsetFilePath = widgetsetBasePath + "/"
- + AbstractApplicationServlet.WIDGETSET_DIRECTORY_PATH
- + widgetset + "/" + widgetset + ".nocache.js?"
- + System.currentTimeMillis();
+ String widgetsetBase = staticFileLocation + "/"
+ + AbstractApplicationServlet.WIDGETSET_DIRECTORY_PATH;
// Get system messages
Application.SystemMessages systemMessages = AbstractApplicationServlet
.getSystemMessages(application.getClass());
+ page.write("<script type=\"text/javascript\" src=\"");
+ page.write(staticFileLocation);
+ page.write("/VAADIN/vaadinBootstrap.js\"></script>\n");
+
page.write("<script type=\"text/javascript\">\n");
page.write("//<![CDATA[\n");
- page.write("if(!vaadin || !vaadin.vaadinConfigurations) {\n "
- + "if(!vaadin) { var vaadin = {}} \n"
- + "vaadin.vaadinConfigurations = {};\n"
- + "if (!vaadin.themesLoaded) { vaadin.themesLoaded = {}; }\n");
- if (!application.isProductionMode()) {
- page.write("vaadin.debug = true;\n");
+
+ JSONObject defaults = new JSONObject();
+ JSONObject appConfig = new JSONObject();
+
+ boolean isDebug = !application.isProductionMode();
+ if (isDebug) {
+ defaults.put("debug", true);
}
+
page.write("document.write('<iframe tabIndex=\"-1\" id=\"__gwt_historyFrame\" "
+ "style=\"position:absolute;width:0;height:0;border:0;overflow:"
+ "hidden;\" src=\"javascript:false\"></iframe>');\n");
- page.write("document.write(\"<script language='javascript' src='"
- + widgetsetFilePath + "'><\\/script>\");\n}\n");
- page.write("vaadin.vaadinConfigurations[\"" + appId + "\"] = {");
- page.write("appUri:'" + appUrl + "', ");
+ defaults.put("appUri", appUrl);
- page.write(ApplicationConnection.ROOT_ID_PARAMETER + ": "
- + root.getRootId() + ", ");
+ appConfig
+ .put(ApplicationConnection.ROOT_ID_PARAMETER, root.getRootId());
if (isStandalone()) {
- page.write("standalone: true, ");
+ defaults.put("standalone", true);
}
- page.write("themeUri:");
- page.write(themeUri != null ? "\"" + themeUri + "\"" : "null");
- page.write(", versionInfo : {vaadinVersion:\"");
- page.write(AbstractApplicationServlet.VERSION);
- page.write("\",applicationVersion:\"");
- page.write(JsonPaintTarget.escapeJSON(application.getVersion()));
- page.write("\"}");
+
+ appConfig.put("themeUri", themeUri);
+
+ JSONObject versionInfo = new JSONObject();
+ versionInfo.put("vaadinVersion", AbstractApplicationServlet.VERSION);
+ versionInfo.put("applicationVersion", application.getVersion());
+ appConfig.put("versionInfo", versionInfo);
+
if (systemMessages != null) {
// Write the CommunicationError -message to client
- String caption = systemMessages.getCommunicationErrorCaption();
- if (caption != null) {
- caption = "\"" + JsonPaintTarget.escapeJSON(caption) + "\"";
- }
- String message = systemMessages.getCommunicationErrorMessage();
- if (message != null) {
- message = "\"" + JsonPaintTarget.escapeJSON(message) + "\"";
- }
- String url = systemMessages.getCommunicationErrorURL();
- if (url != null) {
- url = "\"" + JsonPaintTarget.escapeJSON(url) + "\"";
- }
-
- page.write(",\"comErrMsg\": {" + "\"caption\":" + caption + ","
- + "\"message\" : " + message + "," + "\"url\" : " + url
- + "}");
-
- // Write the AuthenticationError -message to client
- caption = systemMessages.getAuthenticationErrorCaption();
- if (caption != null) {
- caption = "\"" + JsonPaintTarget.escapeJSON(caption) + "\"";
- }
- message = systemMessages.getAuthenticationErrorMessage();
- if (message != null) {
- message = "\"" + JsonPaintTarget.escapeJSON(message) + "\"";
- }
- url = systemMessages.getAuthenticationErrorURL();
- if (url != null) {
- url = "\"" + JsonPaintTarget.escapeJSON(url) + "\"";
- }
-
- page.write(",\"authErrMsg\": {" + "\"caption\":" + caption + ","
- + "\"message\" : " + message + "," + "\"url\" : " + url
- + "}");
+ JSONObject comErrMsg = new JSONObject();
+ comErrMsg.put("caption",
+ systemMessages.getCommunicationErrorCaption());
+ comErrMsg.put("message",
+ systemMessages.getCommunicationErrorMessage());
+ comErrMsg.put("url", systemMessages.getCommunicationErrorURL());
+
+ defaults.put("comErrMsg", comErrMsg);
+
+ JSONObject authErrMsg = new JSONObject();
+ authErrMsg.put("caption",
+ systemMessages.getAuthenticationErrorCaption());
+ authErrMsg.put("message",
+ systemMessages.getAuthenticationErrorMessage());
+ authErrMsg.put("url", systemMessages.getAuthenticationErrorURL());
+
+ defaults.put("authErrMsg", authErrMsg);
}
- page.write("};\n//]]>\n</script>\n");
- if (themeName != null) {
- // Custom theme's stylesheet, load only once, in different
- // script
- // tag to be dominate styles injected by widget
- // set
- page.write("<script type=\"text/javascript\">\n");
- page.write("//<![CDATA[\n");
- page.write("if(!vaadin.themesLoaded['" + themeName + "']) {\n");
- page.write("var stylesheet = document.createElement('link');\n");
- page.write("stylesheet.setAttribute('rel', 'stylesheet');\n");
- page.write("stylesheet.setAttribute('type', 'text/css');\n");
- page.write("stylesheet.setAttribute('href', '" + themeUri
- + "/styles.css');\n");
- page.write("document.getElementsByTagName('head')[0].appendChild(stylesheet);\n");
- page.write("vaadin.themesLoaded['" + themeName + "'] = true;\n}\n");
- page.write("//]]>\n</script>\n");
+ defaults.put("widgetsetBase", widgetsetBase);
+
+ String widgetset = application.getWidgetsetForRoot(root);
+ widgetset = getApplicationOrSystemProperty(request,
+ AbstractApplicationServlet.PARAMETER_WIDGETSET,
+ AbstractApplicationServlet.DEFAULT_WIDGETSET);
+
+ widgetset = AbstractApplicationServlet.stripSpecialChars(widgetset);
+ appConfig.put("widgetset", widgetset);
+
+ page.write("vaadin.setDefaults(");
+ if (isDebug) {
+ page.write(defaults.toString(4));
+ } else {
+ page.write(defaults.toString());
}
+ page.write(");\n");
- // Warn if the widgetset has not been loaded after 15 seconds on
- // inactivity
- page.write("<script type=\"text/javascript\">\n");
- page.write("//<![CDATA[\n");
- page.write("setTimeout('if (typeof " + widgetset.replace('.', '_')
- + " == \"undefined\") {alert(\"Failed to load the widgetset: "
- + widgetsetFilePath + "\")};',15000);\n" + "//]]>\n</script>\n");
+ page.write("vaadin.initApplication(\"");
+ page.write(appId);
+ page.write("\",");
+ if (isDebug) {
+ page.write(appConfig.toString(4));
+ } else {
+ page.write(appConfig.toString());
+ }
+ page.write(");\n");
+ page.write("//]]>\n</script>\n");
}
protected abstract String getApplicationOrSystemProperty(
@@ -439,8 +427,8 @@ public abstract class AjaxPageHandler implements RequestHandler {
protected void writeError(WrappedResponse response, Throwable e)
throws IOException {
- response.setStatus(500);
- response.getWriter().println("Error");
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ e.getLocalizedMessage());
}
}