Package com.oorian.messaging.commands
Class JavaScriptCommand
java.lang.Object
com.oorian.messaging.commands.Command
com.oorian.messaging.commands.JavaScriptCommand
- Direct Known Subclasses:
ScrollIntoView,ScrollToTop
Command to execute JavaScript code or call JavaScript functions on the client side.
This command provides two modes of JavaScript execution:
- Statement mode: Execute arbitrary JavaScript statements
- Function mode: Call a specific JavaScript function with parameters
The command serializes to JSON for transmission to the client, where the JavaScript will be executed in the browser context.
Features:
- Execute JavaScript statements directly
- Call JavaScript functions by name with parameters
- Support for multiple parameter types
Usage:
// Execute a JavaScript statement
JavaScriptCommand jsCmd1 = new JavaScriptCommand("alert('Hello World');");
// Call a JavaScript function with parameters
JavaScriptCommand jsCmd2 = new JavaScriptCommand("myFunction", "param1", 42, true);
// Call a function with a list of parameters
List<Object> params = Arrays.asList("value1", 100, false);
JavaScriptCommand jsCmd3 = new JavaScriptCommand("anotherFunction", params);
- Since:
- 2007
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionJavaScriptCommand(String statement) Constructs a new JavaScriptCommand to execute a JavaScript statement.JavaScriptCommand(String function, Object... parameters) Constructs a new JavaScriptCommand to call a JavaScript function with variable arguments.JavaScriptCommand(String function, List<Object> parameters) Constructs a new JavaScriptCommand to call a JavaScript function with a list of parameters. -
Method Summary
Modifier and TypeMethodDescriptiontoJson()Generates the JSON representation of this JavaScript command.Methods inherited from class com.oorian.messaging.commands.Command
getElementId, getId, setElementId, toString
-
Constructor Details
-
JavaScriptCommand
Constructs a new JavaScriptCommand to execute a JavaScript statement.- Parameters:
statement- the JavaScript code to execute on the client side
-
JavaScriptCommand
Constructs a new JavaScriptCommand to call a JavaScript function with variable arguments.- Parameters:
function- the name of the JavaScript function to callparameters- the parameters to pass to the function
-
JavaScriptCommand
Constructs a new JavaScriptCommand to call a JavaScript function with a list of parameters.- Parameters:
function- the name of the JavaScript function to callparameters- the list of parameters to pass to the function
-
-
Method Details
-
toJson
Generates the JSON representation of this JavaScript command.The JSON structure differs based on mode:
- Statement mode: Includes a "statement" property with the JavaScript code
- Function mode: Includes a "function" property with the function name and a "parameters" array
-