Class JavaScriptCommand

java.lang.Object
com.oorian.messaging.commands.Command
com.oorian.messaging.commands.JavaScriptCommand
Direct Known Subclasses:
ScrollIntoView, ScrollToTop

public class JavaScriptCommand extends Command
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 Details

    • JavaScriptCommand

      public JavaScriptCommand(String statement)
      Constructs a new JavaScriptCommand to execute a JavaScript statement.
      Parameters:
      statement - the JavaScript code to execute on the client side
    • JavaScriptCommand

      public JavaScriptCommand(String function, Object... parameters)
      Constructs a new JavaScriptCommand to call a JavaScript function with variable arguments.
      Parameters:
      function - the name of the JavaScript function to call
      parameters - the parameters to pass to the function
    • JavaScriptCommand

      public JavaScriptCommand(String function, List<Object> parameters)
      Constructs a new JavaScriptCommand to call a JavaScript function with a list of parameters.
      Parameters:
      function - the name of the JavaScript function to call
      parameters - the list of parameters to pass to the function
  • Method Details

    • toJson

      public JsonObject 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
      Specified by:
      toJson in class Command
      Returns:
      a JsonObject containing the JavaScript command data