diff options
author | Leif Åstrand <leif@vaadin.com> | 2011-11-02 14:09:01 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2011-11-02 14:09:01 +0200 |
commit | 432a764e515873f1eb6768a6eb9b15f5fc43ce14 (patch) | |
tree | 982168ec6282b78d89d12d45d07c80f2c13fcc23 /src | |
parent | 04722c351b2b8619884fbedbcdc4d6a50c4e1d55 (diff) | |
download | vaadin-framework-432a764e515873f1eb6768a6eb9b15f5fc43ce14.tar.gz vaadin-framework-432a764e515873f1eb6768a6eb9b15f5fc43ce14.zip |
Restored support for executeJavaScript in Root
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/RootTestApplication.java | 2 | ||||
-rw-r--r-- | src/com/vaadin/ui/DefaultRoot.java | 47 | ||||
-rw-r--r-- | src/com/vaadin/ui/Root.java | 2 | ||||
-rw-r--r-- | src/com/vaadin/ui/Window.java | 57 |
4 files changed, 50 insertions, 58 deletions
diff --git a/src/com/vaadin/RootTestApplication.java b/src/com/vaadin/RootTestApplication.java index 08958d8edc..bf5ec99b00 100644 --- a/src/com/vaadin/RootTestApplication.java +++ b/src/com/vaadin/RootTestApplication.java @@ -9,7 +9,7 @@ public class RootTestApplication extends Application { private final Root root = new DefaultRoot(new Button("Roots, bloody roots", new Button.ClickListener() { public void buttonClick(ClickEvent event) { - root.showNotification("Testing"); + root.executeJavaScript("window.alert(\"Here\");"); } })); diff --git a/src/com/vaadin/ui/DefaultRoot.java b/src/com/vaadin/ui/DefaultRoot.java index 8eb4a26050..7adf5a892a 100644 --- a/src/com/vaadin/ui/DefaultRoot.java +++ b/src/com/vaadin/ui/DefaultRoot.java @@ -1,5 +1,6 @@ package com.vaadin.ui; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -28,6 +29,12 @@ public class DefaultRoot extends AbstractComponentContainer implements Root { private List<Notification> notifications; /** + * A list of javascript commands that are waiting to be sent to the client. + * Cleared (set to null) when the commands have been sent. + */ + private List<String> jsExecQueue = null; + + /** * List of windows in this root. */ private final LinkedHashSet<Window> windows = new LinkedHashSet<Window>(); @@ -92,6 +99,16 @@ public class DefaultRoot extends AbstractComponentContainer implements Root { notifications = null; } + // Add executable javascripts if needed + if (jsExecQueue != null) { + for (String script : jsExecQueue) { + target.startTag("execJS"); + target.addAttribute("script", script); + target.endTag("execJS"); + } + jsExecQueue = null; + } + if (pendingFocus != null) { // ensure focused component is still attached to this main window if (pendingFocus.getRoot() == this @@ -368,4 +385,34 @@ public class DefaultRoot extends AbstractComponentContainer implements Root { notifications.add(notification); requestRepaint(); } + + /** + * Executes JavaScript in this root. + * + * <p> + * This method allows one to inject javascript from the server to client. A + * client implementation is not required to implement this functionality, + * but currently all web-based clients do implement this. + * </p> + * + * <p> + * Executing javascript this way often leads to cross-browser compatibility + * issues and regressions that are hard to resolve. Use of this method + * should be avoided and instead it is recommended to create new widgets + * with GWT. For more info on creating own, reusable client-side widgets in + * Java, read the corresponding chapter in Book of Vaadin. + * </p> + * + * @param script + * JavaScript snippet that will be executed. + */ + public void executeJavaScript(String script) { + if (jsExecQueue == null) { + jsExecQueue = new ArrayList<String>(); + } + + jsExecQueue.add(script); + + requestRepaint(); + } } diff --git a/src/com/vaadin/ui/Root.java b/src/com/vaadin/ui/Root.java index 332220f88d..30659d98e3 100644 --- a/src/com/vaadin/ui/Root.java +++ b/src/com/vaadin/ui/Root.java @@ -50,4 +50,6 @@ public interface Root extends Component, com.vaadin.ui.Component.Focusable { public void showNotification(String caption); + public void executeJavaScript(String script); + } diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index 7366f90874..4c72ecf844 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -163,14 +163,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { */ private boolean resizeLazy = false; - // /** - // * <b>Application window only</b>. A list of javascript commands that are - // * waiting to be sent to the client. Cleared (set to null) when the - // commands - // * have been sent. - // */ - // private ArrayList<String> jsExecQueue = null; - /** * The component that should be scrolled into view after the next repaint. * Null if nothing should be scrolled into view. @@ -473,16 +465,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { // Contents of the window panel is painted super.paintContent(target); - // // Add executable javascripts if needed - // if (jsExecQueue != null) { - // for (String script : jsExecQueue) { - // target.startTag("execJS"); - // target.addAttribute("script", script); - // target.endTag("execJS"); - // } - // jsExecQueue = null; - // } - // Window position target.addVariable(this, "positionx", getPositionX()); target.addVariable(this, "positiony", getPositionY()); @@ -1590,45 +1572,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier { } } - // /** - // * Executes JavaScript in this window. - // * - // * <p> - // * This method allows one to inject javascript from the server to client. - // A - // * client implementation is not required to implement this functionality, - // * but currently all web-based clients do implement this. - // * </p> - // * - // * <p> - // * Executing javascript this way often leads to cross-browser - // compatibility - // * issues and regressions that are hard to resolve. Use of this method - // * should be avoided and instead it is recommended to create new widgets - // * with GWT. For more info on creating own, reusable client-side widgets - // in - // * Java, read the corresponding chapter in Book of Vaadin. - // * </p> - // * - // * @param script - // * JavaScript snippet that will be executed. - // */ - // public void executeJavaScript(String script) { - // - // if (getParent() != null) { - // throw new UnsupportedOperationException( - // "Only application level windows can execute javascript."); - // } - // - // if (jsExecQueue == null) { - // jsExecQueue = new ArrayList<String>(); - // } - // - // jsExecQueue.add(script); - // - // requestRepaint(); - // } - /** * Returns the closable status of the sub window. If a sub window is * closable it typically shows an X in the upper right corner. Clicking on |