Interface JavaScriptComponent

All Superinterfaces:
Component, Component.BelongToFrame, Component.HasCaption, Component.HasDescription, Component.HasIcon, HasContextHelp, HasRequiredIndicator
All Known Implementing Classes:
JavaScriptComponentImpl

@StudioComponent(caption="JavaScriptComponent", category="Containers", xmlElement="jsComponent", icon="io/jmix/ui/icon/container/jsComponent.svg", canvasBehaviour=BOX, documentationURL="https://docs.jmix.io/jmix/%VERSION%/ui/custom-components/js-component.html") public interface JavaScriptComponent extends Component, Component.HasCaption, Component.HasDescription, Component.HasIcon, Component.BelongToFrame, HasContextHelp, HasRequiredIndicator
A JavaScript wrapper.
  • Field Details

  • Method Details

    • getDependencies

      Returns:
      a list of dependencies
    • setDependencies

      void setDependencies(List<JavaScriptComponent.ClientDependency> dependencies)
      Sets a list of dependencies. Each dependency represented with a JavaScriptComponent.ClientDependency object which path corresponds to one of the sources:
      • WebJar resource - starts with webjar://
      • VAADIN directory - starts with vaadin://
      Parameters:
      dependencies - dependencies to set
    • addDependency

      void addDependency(String path, JavaScriptComponent.DependencyType type)
      Adds a dependency. Path path corresponds to one of the sources:
      • WebJar resource - starts with webjar://
      • VAADIN directory - starts with vaadin://
      Parameters:
      path - a dependency path
      type - a dependency type
    • addDependencies

      void addDependencies(String... dependencies)
      Adds dependency paths. Each path corresponds to one of the sources:
      • WebJar resource - starts with webjar://
      • VAADIN directory - starts with vaadin://
      Parameters:
      dependencies - dependencies to add
    • getInitFunctionName

      String getInitFunctionName()
      Returns:
      an initialization function name that will be used to find an entry point for the JS component connector
    • setInitFunctionName

      @StudioProperty void setInitFunctionName(String initFunctionName)
      Sets an initialization function name that will be used to find an entry point for the JS component connector.

      CAUTION: the initialization function name must be unique within window.

      Parameters:
      initFunctionName - an initialization function name
    • getState

      Object getState()
      Returns:
      Returns a state object
    • setState

      void setState(Object state)
      Sets a state object that can be used in the client-side JS connector and accessible from the data field of the component's state.

      Here an example of accessing the state object:

      
       connector.onStateChange = function () {
          var state = connector.getState();
          let data = state.data;
          ...
       }
       

      The state object should be a POJO.

      CAUTION: Date fields serialized as strings with DateJsonSerializer.DATE_FORMAT format.

      Parameters:
      state - a state object to set
    • addFunction

      void addFunction(String name, Consumer<JavaScriptComponent.JavaScriptCallbackEvent> function)
      Register a Consumer that can be called from the JavaScript using the provided name. A JavaScript function with the provided name will be added to the connector wrapper object (initially available as this). Calling that JavaScript function will cause the call method in the registered Consumer to be invoked with the same arguments passed to the JavaScriptComponent.JavaScriptCallbackEvent.
      Parameters:
      name - the name that should be used for client-side function
      function - the Consumer object that will be invoked when the JavaScript function is called
    • callFunction

      void callFunction(String name, Object... arguments)
      Invoke a named function that the connector JavaScript has added to the JavaScript connector wrapper object. The arguments can be any boxed primitive type, String, JsonValue or arrays of any other supported type. Complex types (e.g. List, Set, Map, Connector or any JavaBean type) must be explicitly serialized to a JsonValue before sending.
      Parameters:
      name - the name of the function
      arguments - function arguments
    • repaint

      void repaint()
      Repaint UI representation of the component.