@StudioComponent(caption="JavaScriptComponent", category="Containers", xmlElement="jsComponent", icon="io/jmix/ui/icon/container/jsComponent.svg", canvasBehaviour=BOX, documentationURL="https://docs.jmix.io/jmix/%VERSION%/backoffice-ui/vcl/components/js-component.html") public interface JavaScriptComponent extends Component, Component.HasCaption, Component.HasDescription, Component.HasIcon, Component.BelongToFrame, HasContextHelp, HasRequiredIndicator
Modifier and Type | Interface and Description |
---|---|
static class |
JavaScriptComponent.ClientDependency |
static class |
JavaScriptComponent.DependencyType
The type of dependency.
|
static class |
JavaScriptComponent.JavaScriptCallbackEvent
An event that is fired when a method is called by a client-side JavaScript function.
|
Component.Alignment, Component.BelongToFrame, Component.Disposable, Component.Editable, Component.Focusable, Component.HasCaption, Component.HasDescription, Component.HasIcon, Component.HasXmlDescriptor, Component.Wrapper
HasContextHelp.ContextHelpIconClickEvent
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NAME |
AUTO_SIZE, AUTO_SIZE_PX, FULL_SIZE
Modifier and Type | Method and Description |
---|---|
void |
addDependencies(java.lang.String... dependencies)
Adds dependency paths.
|
void |
addDependency(java.lang.String path,
JavaScriptComponent.DependencyType type)
Adds a dependency.
|
void |
addFunction(java.lang.String name,
java.util.function.Consumer<JavaScriptComponent.JavaScriptCallbackEvent> function)
Register a
Consumer that can be called from the
JavaScript using the provided name. |
void |
callFunction(java.lang.String name,
java.lang.Object... arguments)
Invoke a named function that the connector JavaScript has added to the
JavaScript connector wrapper object.
|
java.util.List<JavaScriptComponent.ClientDependency> |
getDependencies() |
java.lang.String |
getInitFunctionName() |
java.lang.Object |
getState() |
void |
repaint()
Repaint UI representation of the component.
|
void |
setDependencies(java.util.List<JavaScriptComponent.ClientDependency> dependencies)
Sets a list of dependencies.
|
void |
setInitFunctionName(java.lang.String initFunctionName)
Sets an initialization function name that will be
used to find an entry point for the JS component connector.
|
void |
setState(java.lang.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. |
getCaption, setCaption
getDescription, setDescription
getIcon, setIcon, setIconFromSet
getFrame, setFrame
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
getContextHelpIconClickHandler, getContextHelpText, isContextHelpTextHtmlEnabled, setContextHelpIconClickHandler, setContextHelpText, setContextHelpTextHtmlEnabled
isRequiredIndicatorVisible, setRequiredIndicatorVisible
static final java.lang.String NAME
java.util.List<JavaScriptComponent.ClientDependency> getDependencies()
void setDependencies(java.util.List<JavaScriptComponent.ClientDependency> dependencies)
JavaScriptComponent.ClientDependency
object which path corresponds to one of the sources:
webjar://
vaadin://
dependencies
- dependencies to setvoid addDependency(java.lang.String path, JavaScriptComponent.DependencyType type)
webjar://
vaadin://
path
- a dependency pathtype
- a dependency typevoid addDependencies(java.lang.String... dependencies)
webjar://
vaadin://
dependencies
- dependencies to addjava.lang.String getInitFunctionName()
@StudioProperty void setInitFunctionName(java.lang.String initFunctionName)
CAUTION: the initialization function name must be unique within window.
initFunctionName
- an initialization function namejava.lang.Object getState()
void setState(java.lang.Object state)
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.
state
- a state object to setvoid addFunction(java.lang.String name, java.util.function.Consumer<JavaScriptComponent.JavaScriptCallbackEvent> function)
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
.name
- the name that should be used for client-side functionfunction
- the Consumer
object that will be invoked
when the JavaScript function is calledvoid callFunction(java.lang.String name, java.lang.Object... arguments)
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.name
- the name of the functionarguments
- function argumentsvoid repaint()