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.
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.
var form =solutionModel.newForm('mediaForm','db:/example_data/parent_table',null,false,400,300);var strechAllDirectionsLabel =form.newLabel('Strech all directions',10,10,380,280);strechAllDirectionsLabel.background ='red';strechAllDirectionsLabel.anchors =SM_ANCHOR.ALL;var strechVerticallyLabel =form.newLabel('Strech vertically',10,10,190,280);strechVerticallyLabel.background ='green';strechVerticallyLabel.anchors =SM_ANCHOR.WEST|SM_ANCHOR.NORTH|SM_ANCHOR.SOUTH;var strechHorizontallyLabel =form.newLabel('Strech horizontally',10,10,380,140);strechHorizontallyLabel.background ='blue';strechHorizontallyLabel.anchors =SM_ANCHOR.NORTH|SM_ANCHOR.WEST|SM_ANCHOR.EAST;var stickToTopLeftCornerLabel =form.newLabel('Stick to top-left corner',10,10,200,100);stickToTopLeftCornerLabel.background ='orange';stickToTopLeftCornerLabel.anchors =SM_ANCHOR.NORTH|SM_ANCHOR.WEST; // This is equivalent to SM_ANCHOR.DEFAULTvar stickToBottomRightCornerLabel =form.newLabel('Stick to bottom-right corner',190,190,200,100);stickToBottomRightCornerLabel.background ='pink';stickToBottomRightCornerLabel.anchors =SM_ANCHOR.SOUTH|SM_ANCHOR.EAST;
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.
var form =solutionModel.newForm('printForm','db:/example_data/parent_table',null,false,400,300);var field =form.newField('parent_table_text',JSField.TEXT_FIELD,10,10,100,20);field.enabled =false;
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.
var form =solutionModel.newForm('someForm','db:/example_data/parent_table',null,false,620,300);var label =form.newLabel('Label',10,10,150,150);label.name ='myLabel'; // Give a name to the component.forms['someForm'].controller.show()// Now use the name to access the component.forms['someForm'].elements['myLabel'].text ='Updated text';
var form =solutionModel.newForm('printForm','db:/example_data/parent_table',null,false,400,300);var field =form.newField('parent_table_text',JSField.TEXT_FIELD,10,10,100,20);field.visible =false;
var frm =solutionModel.getForm('orders')var fld =frm.getField('fld')var attributes =fld.getAttributes();for (var i =0; i <attributes.length; i++){application.output(fld.getAttribute(attributes[i]));}
var frm =solutionModel.getForm('orders')var fld =frm.getField('fld')var attributes =fld.getAttributes();for (var i =0; i <attributes.length; i++){application.output(fld.getAttribute(attributes[i]));}
var wc =form.getWebComponent('mycomponent');var handler =wc.getHandler('onActionMethodID');
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
StringpropertyName the name of the property to get
var wc =form.getWebComponent('mycomponent');application.output(wc.getJSONProperty('mytext')); // will output a string value if present for a string typed propertyapplication.output(wc.getJSONProperty('mynumber')); // getter will return a number if presentapplication.output(JSON.stringify(wc.getJSONProperty('mycustomtype'),null,' ')); // getter returns an object if present for custom types is spec filesapplication.output(JSON.stringify(wc.getJSONProperty('myarray'),null,' ')); // getter returns an array type if present for array typesapplication.output(JSON.stringify(wc.getJSONProperty('myfoundset'),null,' ')); // getter returns an object representing the design settings of the given property if present//In case you want to change a more complex property (e.g. tabs) obtained with getJSONProperty, setJSONProperty must be used:var tabs =jsTabPanel.getJSONPRoperty("tabs");tabs[0].containsFormId = jsForm;jsTabPanel.setJSONProperty("tabs", tabs);
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
BooleanincludeAll whether to return all properties from specification file or only the ones that are set in json
var wc =form.getWebComponent('mycomponent');application.output(wc.getJSONPropertyNames(true)); // will output all property names from the spec fileapplication.output(wc.getJSONPropertyNames(false)); // will output all property names that are set in component json
var wc =form.getWebComponent('mycomponent');var isSet =wc.isJSONPropertySet(''mytext''); // returns falsewc.setJSONProperty('mytext','Hello World Extended!');isSet =wc.isJSONPropertySet(''mytext''); // returns true
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.
var frm =solutionModel.getForm('orders')var fld =frm.getField('fld')fld.removeDesignTimeProperty('myprop')
resetHandler(handlerName)
Similar to resetJSONProperty but for handlers.
Parameters
StringhandlerName the name of the handler to reset
Returns: void
Sample
var wc =form.getWebComponent('mycomponent'); // form is extending another form who's 'onActionMethodID' does something nicewc.setHandler('onActionMethodID',form.getMethod('onCoolerAction'));// hmm, I changed my mind - I like 'nice' action betterwc.resetHandler('onActionMethodID');
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
StringpropertyName the name of the property to reset
Returns: void
Sample
var wc =form.getWebComponent('mycomponent'); // form is extending another form who's 'mycomponent' has property 'mytext' set to something...wc.setJSONProperty('mytext','Hello World Extended!');// hmm I changed my mind - I like simple 'Hello World' betterwc.resetJSONProperty('mytext');
var frm =solutionModel.getForm('orders')var fld =frm.getField('fld')fld.setAttribute('keylistener','callback')
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.
JSMethodmethod the JSMethod to attach to the handler (can be also JSMethod that has arguments)
Returns: void
Sample
var wc =form.getWebComponent('mycomponent');wc.setHandler('onActionMethodID',form.getMethod('onAction'));
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
StringpropertyName the name of the property to set
var wc =form.getWebComponent('mycomponent');wc.setJSONProperty('mytext','Hello World!');wc.setJSONProperty('mynumber',1);wc.setJSONProperty('myborder','LineBorder,1,#ccffcc');wc.setJSONProperty('mydynamicfoundset', { dataproviders: { dp1:"city", dp2:"country" }, foundsetSelector:"" }); // foundset property type using// the parent form's foundset and providing two columns of the foundset to client; see foundset property type wiki page for more information