/** * 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); }
/** * Call the dwr.engine.remote.handleResponse() in the browser * @param batchId The identifier of the batch that we are handling a response for * @param callId The identifier of the call that we are handling a response for * @param data The data to pass to the callback function * @return The script to send to the browser */ public static ScriptBuffer getRemoteHandleCallbackScript(String batchId, String callId, Object data) { ScriptBuffer script = new ScriptBuffer(); script.appendCall("dwr.engine.remote.handleCallback", batchId, callId, data); return 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 * @return this. To allow buffer.append(x).append(y).append(z); * @see org.directwebremoting.ScriptSessions#addFunctionCall */ public ScriptBuffer appendCall(String funcName, Object... params) { appendScript(funcName); appendScript("("); for (int i = 0; i < params.length; i++) { if (i != 0) { appendScript(","); } appendData(params[i]); } appendScript(");"); return this; }
/** * 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); }
/** * Call a named function with no parameters. * @param funcName The name of the function to call */ public void addFunctionCall(String funcName) { ScriptBuffer script = new ScriptBuffer(); script.appendScript(funcName) .appendScript("();"); addScript(script); }
/** * 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)); }
/** * Create a ScriptBuffer with some initial content. * {@link #appendScript(String)} is called with the passed string * @param str The initial string to place in the buffer */ public ScriptBuffer(String str) { appendScript(str); }
for (Object part : script.getParts())
public void toJson(Object data, Writer out) throws IOException { // Get the output stream and setup the mime type try { ScriptBuffer buffer = new ScriptBuffer(); buffer.appendData(data); String output = ScriptBufferUtil.createOutput(buffer, converterManager, true); out.write(output); } catch (ConversionException ex) { log.warn("--ConversionException: class=" + ex.getConversionType().getName(), ex); ScriptBuffer buffer = new ScriptBuffer(); buffer.appendData(ex); try { String output = ScriptBufferUtil.createOutput(buffer, converterManager, true); out.write(output); } catch (ConversionException ex1) { log.error("--Nested ConversionException: Is there an exception handler registered? class=" + ex.getConversionType().getName(), ex); } } }
/** * @param elementId The element to affect * @param function The script.aculo.us effect to employ * @param options A string containing options to pass to the script.aculo.us effect, as specified at http://script.aculo.us/ */ private void callEffect(String elementId, String function, String options) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("new Effect.").appendScript(function).appendScript("('").appendScript(elementId).appendScript("'"); if (options != null && options.length() > 0) { script.appendScript(", ").appendScript(options); } script.appendScript(");"); addScript(script); } }
public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception { ScriptSession session = WebContextFactory.get().getScriptSession(); Long lastAccess = (Long) session.getAttribute(ATTRIBUTE_LAST_ACTION); // Free pass in if you've not done anything so far. if (lastAccess != null) { long now = System.currentTimeMillis(); if (now > lastAccess + actionTimeoutMillis) { session.addScript(new ScriptBuffer(onTimeout)); session.invalidate(); throw new DwrConvertedException("Your session has timed out"); } } Object reply = chain.doFilter(obj, method, params); session.setAttribute(ATTRIBUTE_LAST_ACTION, System.currentTimeMillis()); return reply; }
/** * Set the preferred remoting type. * @param newType One of dwr.engine.XMLHttpRequest or dwr.engine.IFrame or dwr.engine.ScriptTag */ public void setRpcType(int newType) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setRpcType(") .appendData(newType) .appendScript(");"); addScript(script); }
/** * Call dwr.engine.remote.executeFunction() in the browser * @param id The registered function name * @param propertyName The name of the property to alter on the client object * @param data The new value for the client object property * @return The script to send to the browser */ public static ScriptBuffer getRemoteSetObjectScript(String id, String propertyName, Object data) { ScriptBuffer script = new ScriptBuffer(); script.appendCall("dwr.engine.remote.handleSetCall", id, propertyName, data); return script; }
ScriptBuffer buffer = new ScriptBuffer(); buffer.appendData(data); ScriptBuffer buffer = new ScriptBuffer(); buffer.appendData(ex);
/** * Does DWR us comet polling? (Default: true) * @param pollComet True/False to use Comet where supported */ public void setPollUsingComet(boolean pollComet) { ScriptBuffer script = new ScriptBuffer(); script.appendScript("dwr.engine.setPollUsingComet(") .appendData(pollComet) .appendScript(");"); addScript(script); }
/** * Call dwr.engine.remote.executeFunction() in the browser * @param id The registered function name * @param params The data to pass to the function * @return The script to send to the browser */ public static ScriptBuffer getRemoteExecuteFunctionScript(String id, Object[] params) { ScriptBuffer script = new ScriptBuffer(); script.appendCall("dwr.engine.remote.handleFunctionCall", id, params); return script; }
/** * Sets a CSS style on an element * @param elementId The HTML element to update (by id) */ public 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; }"); addScript(script); }
/** * Call dwr.engine.remote.executeFunction() in the browser * @param id The registered function name * @param params The data to pass to the function * @return The script to send to the browser */ public static ScriptBuffer getRemoteExecuteObjectScript(String id, String methodName, Object[] params) { ScriptBuffer script = new ScriptBuffer(); script.appendCall("dwr.engine.remote.handleObjectCall", id, methodName, params); return 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); }
/** * Call dwr.engine.remote.closeFunction() in the browser * @param id The registered function name * @return The script to send to the browser */ public static ScriptBuffer getRemoteCloseFunctionScript(String id) { ScriptBuffer script = new ScriptBuffer(); script.appendCall("dwr.engine.remote.handleFunctionClose", id); return script; }