Package io.jmix.ui.component
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.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
static enum
The type of dependency.static class
An event that is fired when a method is called by a client-side JavaScript function.Nested classes/interfaces inherited from interface io.jmix.ui.component.Component
Component.Alignment, Component.BelongToFrame, Component.Disposable, Component.Editable, Component.Focusable, Component.HasCaption, Component.HasDescription, Component.HasIcon, Component.HasXmlDescriptor, Component.Wrapper
Nested classes/interfaces inherited from interface io.jmix.ui.component.HasContextHelp
HasContextHelp.ContextHelpIconClickEvent
-
Field Summary
Fields inherited from interface io.jmix.ui.component.Component
AUTO_SIZE, AUTO_SIZE_PX, FULL_SIZE
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDependencies
(String... dependencies) Adds dependency paths.void
addDependency
(String path, JavaScriptComponent.DependencyType type) Adds a dependency.void
addFunction
(String name, Consumer<JavaScriptComponent.JavaScriptCallbackEvent> function) Register aConsumer
that can be called from the JavaScript using the provided name.void
callFunction
(String name, Object... arguments) Invoke a named function that the connector JavaScript has added to the JavaScript connector wrapper object.getState()
void
repaint()
Repaint UI representation of the component.void
setDependencies
(List<JavaScriptComponent.ClientDependency> dependencies) Sets a list of dependencies.void
setInitFunctionName
(String initFunctionName) Sets an initialization function name that will be used to find an entry point for the JS component connector.void
Sets a state object that can be used in the client-side JS connector and accessible from thedata
field of the component's state.Methods inherited from interface io.jmix.ui.component.Component
addStyleName, getAlignment, getHeight, getHeightSizeUnit, getId, getParent, getStyleName, getWidth, getWidthSizeUnit, isEnabled, isEnabledRecursive, isResponsive, isVisible, isVisibleRecursive, removeStyleName, setAlignment, setEnabled, setHeight, setHeightAuto, setHeightFull, setId, setParent, setResponsive, setSizeAuto, setSizeFull, setStyleName, setVisible, setWidth, setWidthAuto, setWidthFull, unwrap, unwrapComposition, unwrapCompositionOrNull, unwrapOrNull, withUnwrapped, withUnwrappedComposition
Methods inherited from interface io.jmix.ui.component.Component.BelongToFrame
getFrame, setFrame
Methods inherited from interface io.jmix.ui.component.Component.HasCaption
getCaption, setCaption
Methods inherited from interface io.jmix.ui.component.Component.HasDescription
getDescription, setDescription
Methods inherited from interface io.jmix.ui.component.Component.HasIcon
getIcon, setIcon, setIconFromSet
Methods inherited from interface io.jmix.ui.component.HasContextHelp
getContextHelpIconClickHandler, getContextHelpText, isContextHelpTextHtmlEnabled, setContextHelpIconClickHandler, setContextHelpText, setContextHelpTextHtmlEnabled
Methods inherited from interface io.jmix.ui.component.HasRequiredIndicator
isRequiredIndicatorVisible, setRequiredIndicatorVisible
-
Field Details
-
NAME
- See Also:
-
-
Method Details
-
getDependencies
List<JavaScriptComponent.ClientDependency> getDependencies()- Returns:
- a list of dependencies
-
setDependencies
Sets a list of dependencies. Each dependency represented with aJavaScriptComponent.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
- WebJar resource - starts with
-
addDependency
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 pathtype
- a dependency type
- WebJar resource - starts with
-
addDependencies
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
- WebJar resource - starts with
-
getInitFunctionName
String getInitFunctionName()- Returns:
- an initialization function name that will be used to find an entry point for the JS component connector
-
setInitFunctionName
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
Sets a state object that can be used in the client-side JS connector and accessible from thedata
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 withDateJsonSerializer.DATE_FORMAT
format.- Parameters:
state
- a state object to set
-
addFunction
Register aConsumer
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 asthis
). Calling that JavaScript function will cause the call method in the registeredConsumer
to be invoked with the same arguments passed to theJavaScriptComponent.JavaScriptCallbackEvent
.- Parameters:
name
- the name that should be used for client-side functionfunction
- theConsumer
object that will be invoked when the JavaScript function is called
-
callFunction
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 aJsonValue
before sending.- Parameters:
name
- the name of the functionarguments
- function arguments
-
repaint
void repaint()Repaint UI representation of the component.
-