diff options
4 files changed, 56 insertions, 37 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 0651c79446..bbad6f0df8 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -2005,17 +2005,8 @@ public abstract class AbstractCommunicationManager implements params.put(ApplicationConnection.ROOT_ID_PARAMETER, root.getRootId()); if (sendUIDL) { - // TODO maybe unify w/ AjaxPageHandler & writeUidlResponCe()? - makeAllPaintablesDirty(root); - StringWriter sWriter = new StringWriter(); - PrintWriter pWriter = new PrintWriter(sWriter); - pWriter.print("{"); - if (isXSRFEnabled(application)) { - pWriter.print(getSecurityKeyUIDL(combinedRequest)); - } - writeUidlResponce(null, true, pWriter, root, false); - pWriter.print("}"); - params.put("uidl", sWriter.toString()); + String initialUIDL = getInitialUIDL(combinedRequest, root); + params.put("uidl", initialUIDL); } response.getWriter().write(params.toString()); } catch (RootRequiresMoreInformation e) { @@ -2029,6 +2020,34 @@ public abstract class AbstractCommunicationManager implements } /** + * 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. + * + * @param request + * the request that caused the initialization + * @param root + * the root for which the UIDL should be generated + * @return a string with the initial UIDL message + * @throws PaintException + * if an exception occurs while painting + */ + protected String getInitialUIDL(WrappedRequest request, Root root) + throws PaintException { + // TODO maybe unify writeUidlResponCe()? + makeAllPaintablesDirty(root); + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter(sWriter); + pWriter.print("{"); + if (isXSRFEnabled(root.getApplication())) { + pWriter.print(getSecurityKeyUIDL(request)); + } + writeUidlResponce(null, true, pWriter, root, false); + pWriter.print("}"); + String initialUIDL = sWriter.toString(); + return initialUIDL; + } + + /** * Stream that extracts content from another stream until the boundary * string is encountered. * diff --git a/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java b/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java index b301a0c801..32523cef88 100644 --- a/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java +++ b/src/com/vaadin/terminal/gwt/server/AjaxPageHandler.java @@ -7,8 +7,6 @@ package com.vaadin.terminal.gwt.server; import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.StringWriter; import java.io.Writer; import javax.servlet.http.HttpServletResponse; @@ -27,14 +25,6 @@ import com.vaadin.ui.Root; public abstract class AjaxPageHandler implements RequestHandler { - /** - * Returns the {@link AbstractCommunicationManager} that is handling the - * communication for the active application. - * - * @return the {@link AbstractCommunicationManager} - */ - protected abstract AbstractCommunicationManager getCommunicationManager(); - protected class AjaxPageContext { private final WrappedResponse response; private final WrappedRequest request; @@ -389,18 +379,8 @@ public abstract class AjaxPageHandler implements RequestHandler { appConfig.put("initPending", true); } else { // write the initial UIDL into the config - AbstractCommunicationManager manager = getCommunicationManager(); - Root root = Root.getCurrentRoot(); - manager.makeAllPaintablesDirty(root); - StringWriter sWriter = new StringWriter(); - PrintWriter pWriter = new PrintWriter(sWriter); - pWriter.print("{"); - if (manager.isXSRFEnabled(application)) { - pWriter.print(manager.getSecurityKeyUIDL(context.getRequest())); - } - manager.writeUidlResponce(null, true, pWriter, root, false); - pWriter.print("}"); - appConfig.put("uidl", sWriter.toString()); + appConfig.put("uidl", + getInitialUIDL(context.getRequest(), context.getRoot())); } return appConfig; @@ -599,4 +579,18 @@ public abstract class AjaxPageHandler implements RequestHandler { e.getLocalizedMessage()); } + /** + * Gets the initial UIDL message to send to the client. + * + * @param request + * the originating request + * @param root + * the root for which the UIDL should be generated + * @return a string with the initial UIDL message + * @throws PaintException + * if an exception occurs while painting the components + */ + protected abstract String getInitialUIDL(WrappedRequest request, Root root) + throws PaintException; + } diff --git a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java index e660e14a8f..2e908ae12a 100644 --- a/src/com/vaadin/terminal/gwt/server/CommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/CommunicationManager.java @@ -11,12 +11,14 @@ import java.util.Map; import java.util.UUID; import com.vaadin.Application; +import com.vaadin.terminal.PaintException; import com.vaadin.terminal.Paintable; import com.vaadin.terminal.StreamVariable; import com.vaadin.terminal.VariableOwner; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedResponse; import com.vaadin.ui.Component; +import com.vaadin.ui.Root; /** * Application manager processes changes and paints for single application @@ -230,8 +232,9 @@ public class CommunicationManager extends AbstractCommunicationManager { } @Override - protected AbstractCommunicationManager getCommunicationManager() { - return CommunicationManager.this; + protected String getInitialUIDL(WrappedRequest request, Root root) + throws PaintException { + return CommunicationManager.this.getInitialUIDL(request, root); } }; } diff --git a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java index f6fb1ac43a..eef3b36522 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManager.java @@ -18,6 +18,7 @@ import com.vaadin.Application; import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; import com.vaadin.terminal.DeploymentConfiguration; +import com.vaadin.terminal.PaintException; import com.vaadin.terminal.Paintable; import com.vaadin.terminal.StreamVariable; import com.vaadin.terminal.VariableOwner; @@ -203,8 +204,10 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { } @Override - protected AbstractCommunicationManager getCommunicationManager() { - return PortletCommunicationManager.this; + protected String getInitialUIDL(WrappedRequest request, Root root) + throws PaintException { + return PortletCommunicationManager.this.getInitialUIDL(request, + root); } }; |