/** * Utility to add the given script to all known browsers. * @param script The Javascript to send to the browsers */ public static void addScript(String script) { ScriptSessions.addScript(script); } }
/** * Utility to add the given script to all known browsers. * @param script The Javascript to send to the browsers */ public static void addScript(ScriptBuffer script) { ScriptSessions.addScript(script); }
/** * This would be good, but it doesn't work on some browsers * @param title The page to navigate to */ public static void setTitle(String title) { ScriptSessions.addScript(("document.title = '" + JavascriptUtil.escapeJavaScript(title) + "';")); } }
/** * Utility to add the given script to all known browsers. * This version automatically wraps the string in a ClientScript object. * @param scriptString The Javascript to send to the browsers */ public static void addScript(String scriptString) { addScript(new ScriptBuffer(scriptString)); }
/** * Navigate to a new page * @param newPage The page to navigate to */ public static void setLocation(String newPage) { ScriptBuffer script = new ScriptBuffer(); script.appendData("window.location = '" + newPage + "';"); ScriptSessions.addScript(script); }
/** * Add a cookie to a remote browser/browsers */ public static void setCookie(Cookie cookie) { String name = JavascriptUtil.escapeJavaScript(cookie.getName()); String value = JavascriptUtil.escapeJavaScript(cookie.getValue()); String domain = cookie.getDomain() == null ? "" : ";domain=" + JavascriptUtil.escapeJavaScript(cookie.getDomain()); String path = cookie.getPath() == null ? "" : ";path=" + JavascriptUtil.escapeJavaScript(cookie.getPath()); String maxAge = cookie.getMaxAge() == -1 ? "" : ";max-age=" + cookie.getMaxAge(); String secure = !cookie.getSecure() ? "" : ";secure=true"; ScriptSessions.addScript(("document.cookie = \"" + name + "=" + value + domain + path + maxAge + secure + "\"")); }
/** * Add a cookie to a remote browser/browsers */ public static void setCookie(String name, String value) { ScriptSessions.addScript(("document.cookie = \"" + JavascriptUtil.escapeJavaScript(name) + "=" + JavascriptUtil.escapeJavaScript(value) + "\"")); }
/** * Does DWR us comet polling? (Default: true) * @param pollComet True/False to use Comet where supported */ public static void setPollUsingComet(boolean pollComet) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setPollUsingComet(") .appendData(pollComet) .appendScript(");"); ScriptSessions.addScript(script); }
/** * Do we ask the XHR object to be asynchronous? (Default: true) * @param async False to become synchronous (not recommended) */ public static void setAsync(boolean async) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setAsync(") .appendData(async) .appendScript(");"); ScriptSessions.addScript(script); }
/** * Set a default timeout value for all calls. 0 (the default) turns timeouts off. * @param timeout The time to wait in milliseconds */ public static void setTimeout(int timeout) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setTimeout(") .appendData(timeout) .appendScript(");"); ScriptSessions.addScript(script); }
/** * Set the preferred remoting type. * @param newType One of dwr.engine.XMLHttpRequest or dwr.engine.IFrame or dwr.engine.ScriptTag */ public static void setRpcType(int newType) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setRpcType(") .appendData(newType) .appendScript(");"); ScriptSessions.addScript(script); }
/** * Which HTTP method do we use to send results? Must be one of "GET" or "POST". * @param httpMethod One of {@link #XMLHttpRequest}, {@link #IFrame} or {@link #ScriptTag} */ public static void setHttpMethod(String httpMethod) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setHttpMethod(") .appendData(httpMethod) .appendScript(");"); ScriptSessions.addScript(script); }
/** * Ensure that remote calls happen in the order in which they were sent? (Default: false) * @param ordered True to set call ordering. */ public static void setOrdered(boolean ordered) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setOrdered(") .appendData(ordered) .appendScript(");"); ScriptSessions.addScript(script); }
/** * Does DWR poll the server for updates? (Default: false) * @param activeReverseAjax True/False to turn RA on/off */ public static void setActiveReverseAjax(boolean activeReverseAjax) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setActiveReverseAjax(") .appendData(activeReverseAjax) .appendScript(");"); ScriptSessions.addScript(script); }
/** * Set the preferred polling type. * @param newPollType One of {@link #XMLHttpRequest}, {@link #IFrame} or {@link #ScriptTag} */ public static void setPollType(int newPollType) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setPollUsingComet(") .appendData(newPollType) .appendScript(");"); ScriptSessions.addScript(script); } }
/** * Sets a CSS style on an element * @param elementId The HTML element to update (by id) */ public static void removeNode(String elementId) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.util._temp = dwr.util.byId(") .appendData(elementId) .appendScript("); ") .appendScript("if (dwr.util._temp) { dwr.util._temp.parentNode.removeChild(dwr.util._temp); dwr.util._temp = null; }"); ScriptSessions.addScript(script); }
/** * Show a 'prompt' dialog * @param message The text to go into the alert box * @param callback The function to be called when a browser replies */ public static void prompt(String message, Callback<String> callback) { ScriptBuffer script = new ScriptBuffer(); String callbackPrefix = ""; if (callback != null) { callbackPrefix = "var reply = "; } script.appendCall(callbackPrefix + "prompt", message); if (callback != null) { String key = CallbackHelperFactory.get().saveCallback(callback, String.class); script.appendCall("__System.activateCallback", key, "reply"); } ScriptSessions.addScript(script); }
/** * Call a named function with one parameter. * @param funcName The name of the function to call * @param params The parameters to the above function */ public static void addFunctionCall(String funcName, Object... params) { ScriptBuffer script = new ScriptBuffer(); script.appendScript(funcName).appendScript("("); for (int i = 0; i < params.length; i++) { if (i != 0) { script.appendScript(","); } script.appendData(params[i]); } script.appendScript(");"); addScript(script); } }
/** * Clone a given node. * @param elementId The HTML element to update (by id) * @param idPrefix How do we prefix ids in the cloned version of the node tree * @param idSuffix How do we suffix ids in the cloned version of the node tree */ public static void cloneNode(String elementId, String idPrefix, String idSuffix) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.util.cloneNode(") .appendData(elementId) .appendScript(", { idPrefix:") .appendData(idPrefix) .appendScript(", idSuffix:") .appendData(idSuffix) .appendScript("});"); ScriptSessions.addScript(script); }
/** * Sets a CSS style on an element * @param elementId The HTML element to update (by id) * @param selector The CSS selector to update * @param value The new value for the CSS class on the given element */ public static void setStyle(String elementId, String selector, String value) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.util.byId(") .appendData(elementId) .appendScript(").style.") .appendScript(selector) .appendScript("=") .appendData(value) .appendScript(";"); ScriptSessions.addScript(script); }