Class JavaScriptComponentImpl

All Implemented Interfaces:
AttachNotifier, Component, Component.BelongToFrame, Component.HasCaption, Component.HasDescription, Component.HasIcon, Component.HasXmlDescriptor, Component.Wrapper, HasContextHelp, HasDebugId, HasHtmlCaption, HasHtmlDescription, HasHtmlSanitizer, HasRequiredIndicator, JavaScriptComponent

public class JavaScriptComponentImpl extends AbstractComponent<JmixJavaScriptComponent> implements JavaScriptComponent
  • Constructor Details

    • JavaScriptComponentImpl

      public JavaScriptComponentImpl()
  • Method Details

    • createComponent

      protected JmixJavaScriptComponent createComponent()
    • initComponent

      protected void initComponent(JmixJavaScriptComponent component)
    • getDependencies

      public List<JavaScriptComponent.ClientDependency> getDependencies()
      Specified by:
      getDependencies in interface JavaScriptComponent
      Returns:
      a list of dependencies
    • setDependencies

      public void setDependencies(List<JavaScriptComponent.ClientDependency> dependencies)
      Description copied from interface: JavaScriptComponent
      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://
      Specified by:
      setDependencies in interface JavaScriptComponent
      Parameters:
      dependencies - dependencies to set
    • addDependency

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

      public void addDependencies(String... dependencies)
      Description copied from interface: JavaScriptComponent
      Adds dependency paths. Each path corresponds to one of the sources:
      • WebJar resource - starts with webjar://
      • VAADIN directory - starts with vaadin://
      Specified by:
      addDependencies in interface JavaScriptComponent
      Parameters:
      dependencies - dependencies to add
    • getInitFunctionName

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

      public void setInitFunctionName(String initFunctionName)
      Description copied from interface: JavaScriptComponent
      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.

      Specified by:
      setInitFunctionName in interface JavaScriptComponent
      Parameters:
      initFunctionName - an initialization function name
    • getState

      public Object getState()
      Specified by:
      getState in interface JavaScriptComponent
      Returns:
      Returns a state object
    • setState

      public void setState(Object state)
      Description copied from interface: JavaScriptComponent
      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.

      Specified by:
      setState in interface JavaScriptComponent
      Parameters:
      state - a state object to set
    • addFunction

      public void addFunction(String name, Consumer<JavaScriptComponent.JavaScriptCallbackEvent> function)
      Description copied from interface: JavaScriptComponent
      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.
      Specified by:
      addFunction in interface JavaScriptComponent
      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

      public void callFunction(String name, Object... arguments)
      Description copied from interface: JavaScriptComponent
      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.
      Specified by:
      callFunction in interface JavaScriptComponent
      Parameters:
      name - the name of the function
      arguments - function arguments
    • isRequiredIndicatorVisible

      public boolean isRequiredIndicatorVisible()
      Description copied from interface: HasRequiredIndicator
      Returns whether a required indicator should be shown.
      Specified by:
      isRequiredIndicatorVisible in interface HasRequiredIndicator
      Returns:
      true if a required indicator should be shown, false otherwise
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean visible)
      Description copied from interface: HasRequiredIndicator
      Sets whether a required indicator should be shown.
      Specified by:
      setRequiredIndicatorVisible in interface HasRequiredIndicator
      Parameters:
      visible - true if a required indicator should be shown, false otherwise
    • repaint

      public void repaint()
      Description copied from interface: JavaScriptComponent
      Repaint UI representation of the component.
      Specified by:
      repaint in interface JavaScriptComponent