/** * Add options to a list from an array or map. * @param elementId The HTML element to update (by id) * @param array And array of objects from which to create options * @param property The object property to use for the option value and text */ public static void addOptions(String elementId, Collection<?> array, String property) { ScriptSessions.addFunctionCall("dwr.util.addOptions", elementId, array, property); }
/** * 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); } }
/** * 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) { ScriptSessions.addFunctionCall(funcName, params); }
/** * 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); }
/** * Send some data to the client and have the browser offer it for download * @param ft The data to be downloaded */ public static void openInDownload(FileTransfer ft) { ScriptSessions.addFunctionCall("dwr.engine.openInDownload", ft); }
/** * 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)); }
/** * Remove all the children of a given node. * @param elementId The HTML element to update (by id) */ public static void removeAllRows(String elementId) { ScriptSessions.addFunctionCall("dwr.util.removeAllRows", elementId); }
/** * 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) + "';")); } }
/** * Send some data to the client and have the browser offer it for download * @param blob The data to be downloaded */ public static void openInDownload(byte[] blob) { ScriptSessions.addFunctionCall("dwr.engine.openInDownload", blob); }
/** * 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); }
/** * Send some data to the client and have the browser offer it for download * @param in The data to be downloaded */ public static void openInDownload(InputStream in) { ScriptSessions.addFunctionCall("dwr.engine.openInDownload", in); }
/** * 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 + "\"")); }
/** * Show in an 'alert' dialog * @param message The text to go into the alert box */ public static void alert(String message) { ScriptSessions.addFunctionCall("alert", message); }
/** * 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) + "\"")); }
/** * Attempt to close this window */ public static void close() { ScriptSessions.addFunctionCall("close"); }
/** * 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); }
/** * Open a new browser child window, pointing at given <code>url</code> and * identified with a given <code>windowName</code>. * @see #open(String, String, OptionBuilder) for more details */ public static void open(String url, String windowName) { ScriptSessions.addFunctionCall("open", url, windowName); }
/** * 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); }
/** * Add options to a list from an array or map. * @param elementId The HTML element to update (by id) * @param array An array of strings to use as both value and text of options */ public static void addOptions(String elementId, String[] array) { ScriptSessions.addFunctionCall("dwr.util.addOptions", elementId, array); }
/** * 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); }