JSWebComponent
Overview
JSWebComponent
provides a wrapper for creating and managing web components in the Solution Model. It extends the JSComponent
model and allows developers to define custom behaviors, attributes, and design-time properties. Web components are essential for building dynamic, responsive forms in web-based Servoy applications. ## Functionality
JSWebComponent includes properties such as cssPosition
and anchors
for defining layout behaviors, making it adaptable to resizing and responsive designs. Visibility, dimensions, and coordinates can be controlled via properties like x
, y
, width
, height
, and visible
. The typeName
property identifies the type of web component, as defined in the specification file.
Methods such as getAttribute
, setJSONProperty
, and getHandler
provide tools for managing attributes, design-time properties, and event handlers. These methods enable dynamic configuration and integration of web components into forms. Utilities like getAttributes
and getUUID
facilitate introspection and metadata access.
JSWebComponent supports both design-time and runtime modifications, allowing components to be customized during development or adjusted dynamically at runtime.
For more details, refer to the RuntimeWebComponent section of this documentation.
Extends
Properties Summarized
Enables a component to stick to a specific side of form and/or to grow or shrink when a window is resized.
CSS position is a replacement for anchoring system making it more intuitive to place a component.
Methods Summarized
Returns whatever the design-time value of the given property was set.
Properties Detailed
anchors
Enables a component to stick to a specific side of form and/or to grow or shrink when a window is resized.
If opposite anchors are activated then the component with grow or shrink with the window. For example if Top and Bottom are activated, then the component will grow/shrink when the window is vertically resized. If Left and Right are activated then the component will grow/shrink when the window is horizontally resized.
If opposite anchors are not activated, then the component will keep a constant distance from the sides of the window which correspond to the activated anchors.
Type Number The anchor configuration for the component.
Sample
cssPosition
CSS position is a replacement for anchoring system making it more intuitive to place a component. CSS position should be set on form, an absolute position form can either work with anchoring or with css position. This is only working in NGClient.
Type CSSPosition The CSS position of the component.
Sample
enabled
The enable state of the component, default true.
Type Boolean True if the component is enabled; false otherwise.
Sample
formIndex
The Z index of this component. If two components overlap, then the component with higher Z index is displayed above the component with lower Z index.
Type Number The Z-index of the component.
Sample
height
The height in pixels of the component.
Type Number The width of the component in pixels.
Sample
name
The name of the component. Through this name it can also accessed in methods. Must be a valid javascript name. (no - in the name or start with number)
Type String The name of the component.
Sample
typeName
The webcomponent type (name from the spec).
Type String the type name of the web component, as defined in the specification file.
Sample
visible
The visible property of the component, default true.
Type Boolean True if the component is visible; false otherwise.
Sample
width
The width in pixels of the component.
Type Number The width of the component in pixels.
Sample
x
The x coordinate of the component on the form.
Type Number
Sample
y
The y coordinate of the component on the form.
Type Number The Y-coordinate position of the component.
Sample
Methods Detailed
getAttribute(name)
Get the value of an attribute of the element.
Parameters
String name the name of the attribute
Returns: Object The value of the specified attribute.
Sample
getAttributes()
Returns the attribute names of an element.
Returns: Array An array of attribute names for the component.
Sample
getComment()
Returns the comment of this component.
Returns: String the comment associated with this component.
Sample
getDesignTimeProperty(key)
Get a design-time property of an element.
Parameters
String key the name of the property
Returns: Object The value of the specified design-time property.
Sample
getDesignTimePropertyNames()
Get the design-time properties of an element.
Returns: Array An array of design-time property names for the component.
Sample
getFormName()
Returns the name of the form. (may be empty string as well)
Returns: String The name of the form containing the component.
Sample
getHandler(handlerName)
Returns the JSMethod handler with the given name.
Parameters
String handlerName the name of the handler to get
Returns: JSMethod the JSMethod handler associated with the specified handler name.
Sample
getJSONProperty(propertyName)
Get the design-time value of the given property. If the value was never set and the component has default value for the give property, that value will be returned. To check if the value was set, use isJSONPropertySet.
Parameters
String propertyName the name of the property to get
Returns: Object the design-time value of the specified property, or the default value if not set.
Sample
getJSONPropertyNames(includeAll)
Get the list of property names this component supports. It can return all properties specified in spec file or only the properties that are set in json.
Parameters
Boolean includeAll whether to return all properties from specification file or only the ones that are set in json
Returns: Array an array of property names supported by the web component. Includes all properties or only set properties based on the includeAll parameter.
Sample
getUUID()
Returns the UUID of this component.
Returns: UUID the UUID of this component.
Sample
isJSONPropertySet(propertyName)
Returns whatever the design-time value of the given property was set.
Parameters
String propertyName the name of the property to check
Returns: Boolean true if the specified property is explicitly set, otherwise false.
Sample
putDesignTimeProperty(key, value)
Set a design-time property of an element. Value should be primitive data (string, boolean or number). Complex values should be stringified before call.
Parameters
Returns: Object The previous value of the specified design-time property, or null if none existed.
Sample
removeAttribute(name)
Remove the attribute of an element.
Parameters
String name the name of the attribute
Returns: String the deleted attribute value
Sample
removeDesignTimeProperty(key)
Clear a design-time property of an element.
Parameters
String key the name of the property
Returns: Object The removed value of the specified design-time property.
Sample
resetHandler(handlerName)
Similar to resetJSONProperty but for handlers.
Parameters
String handlerName the name of the handler to reset
Returns: void
Sample
resetJSONProperty(propertyName)
Reset the design-time value of the given property. This makes it as if it was never set. It can be useful when working with form inheritance.
Parameters
String propertyName the name of the property to reset
Returns: void
Sample
setAttribute(name, value)
Set the attribute value of an element.
Parameters
Returns: void
Sample
setHandler(handlerName, method)
Set the JSMethod handler for the given handler name. The handlerName is checked for existence in the component spec file, if the component does not declare this handler, an error is thrown. If the handler is already set, it will be replaced with the new JSMethod.
Parameters
String handlerName the name of the handler to get
JSMethod method the JSMethod to attach to the handler (can be also JSMethod that has arguments)
Returns: void
Sample
setJSONProperty(propertyName, value)
Set the design-time value for the given property. For primitive property types you can just set the value. For more complex property types you can set a JSON value similar to what would be generated in the .frm file if you would design what you need using editor/properties view. Some property types can be assigned values in the runtime accepted format (for example border, font typed properties have a string representation at runtime and here as well).
Parameters
Returns: void
Sample
Last updated
Was this helpful?