Interface ClientScriptOperation


public interface ClientScriptOperation
Operation providing means to execute JavaScript on the client-side.
Since:
5.1.37
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Operation type providing means to execute JavaScript on the client-side.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Serializable
    perform(String script, boolean asynchronous)
    Executes JavaScript code on the client-side, while waiting for its completion.
  • Field Details

  • Method Details

    • perform

      @Nullable @Nullable Serializable perform(String script, boolean asynchronous)
      Executes JavaScript code on the client-side, while waiting for its completion. There are basically two ways to execute script on the client-side:
      Synchronous script execution:

      Script contains a JavaScript function, which will be invoked on the client-side. The return value of the function will be returned by this method.
       // function scriptMethod() {
       //     return 'methodReturnValue';
       // }
       final Serializable returnValue = operation.perform(script, false);
       // returnValue => "methodReturnValue"

      Script contains an expression, which will be evaluated on the client-side. The result of the evaluated expression will be returned by this method.
       // true ? 'methodReturnValue' : 'nothing'
       final Serializable returnValue = operation.perform(script, false);
       // returnValue => "methodReturnValue"

      Script contains one ore more statements, which will be evaluated on the client-side. The result of the evaluated statements will be returned by this method.
      Note:
      The result value depends on the order of the statements, and might differ in some browsers. Usually the first variable or return value will be used. For a more reliable return value use a simple expression or a function reference.
       // function scriptMethod() {
       //     return 'methodReturnValue';
       // }
       // scriptMethod();
       final Serializable returnValue = operation.perform(script, false);
       // returnValue => "methodReturnValue"

      Asynchronous script execution:

      Script contains a JavaScript function, which will be invoked on the client-side. This JavaScript function will be invoked with a callback function for the notification about the completion of the script execution.
      The asynchronous script execution might for example be necessary if it involves user-interaction or asynchronous requests.
       // function scriptMethod(callback) {
       //     var dialog = createRequestDialog();
       //     dialog.on('close', function() {
       //         callback('methodReturnValue');
       //     });
       //     dialog.show();
       // }
       final Serializable returnValue = operation.perform(script, true);
       // returnValue => "methodReturnValue"
      Important:
      The callback must always be notified about the completion of the execution! The server would otherwise wait forever on its completion. In this case the method will not return until the client has been closed.
      Parameters:
      script - The JavaScript code to be executed on the client-side.
      asynchronous - true if the JavaScript code should be executed asynchronously using a callback function, false if the script should be executed and the evaluated return value should be returned.
      Returns:
      The evaluated return value from the client, or null if there is no value to return.
      Since:
      5.1.37