The most powerful way to create reusable components is to create a component that includes a defined contract. The contract is a JSON file that specifies the component's exposed properties, events, and methods. You can specify those properties, events, and methods within the Visualizer interface, and then define the behavior of custom properties, events, and methods by adding code to the component's controller module.
When you create a component, you have a choice of creating a component with or without a contract. A component without a contract is similar to a master in earlier versions of Kony Visualizer, except that it includes a controller module. You can also convert a component that does not have a contract, or an imported master, to a component with a contract.
Once you create a component with a contract, you can control what is exposed to users of the component. You expose only the properties, events, and methods that you want to make available to your target audience, enhancing your ability to rapidly create and deploy digitalapplications for different audiences. The exposed properties, events, and methods are part of the contract.
You can then use the component in other applications, or share your custom components with other digitalapplication developers by publishing them to Kony Marketplace. For more information about using components, see Using Components.
Important: Parent value for components will always be null. In component controller code, this.view.parent will always return a null value.
The following topics provide additional information about creating components:
A component without contract is similar to a Master in earlier versions of Kony Visualizer, except that a component includes a Controller module. You can reuse the component within your application and distribute it via Kony Marketplace. However, you cannot control which of the component's properties, events, and methods are exposed, or create custom properties, events, and methods. To control the exposed properties, events, and methods of a component, create a component with contract.
To create a component without contract, follow these steps:
To create a reusable component that can be published to Kony Marketplace, create a component with contract. Components with a contract use the Kony Reference Architecture: a structured, modular framework based on the Model-View-Controller (MVC) architecture. For more information on how to create a Kony Reference Architecture project, refer Create a Kony Reference Architecture Project.
To create a component with contract, follow these steps:
Each component's controller module contains the JavaScript code associated with the component. You can add additional modules containing any supporting code to the Modules node. The actions Controller module is auto-generated and should not be modified.
Typically, a component comprises multiple widgets. Once you create a component with a contract, you can specify which of the component's widgets to expose to users.
To expose a component's widgets:
You can select a container widget or a child widget of a container widget.
Kony Visualizer displays the Programmatic Key property. You can use the default value or specify a different programmatic key.
Note: The Expose property will allow a component creator to make the widget visible in the form or another component. A developer who is using the component cannot access the widget directly through code.
If you select a container widget, all widgets within the container will be exposed. If you do not want to expose an individual widget within the container widget, select the widget and set its Expose Widget property to Off.
Note: You can set the Expose Widget property of a container widget to Off but expose an individual widget within the container by setting its Expose Widget property to On.
Earlier, the ability to leverage Data panel features for components was not supported in Kony Visualizer. From V8 SP4 Fixpack 20 onwards, you can directly drag and drop services from the Data panel to a component. In addition, you can drag and drop individual parameters of a sample service to a component. This enhancement will enable you to quickly customize components according to your requirement, and reuse them at various places in your Kony Visualizer Classic and Kony Visualizerprojects. Furthermore, you can publish customized components to Kony Marketplace. You can leverage Data Panel support for both components with contract and components without contract. For more information on the Data panel, click here.
Once you drag and drop a sample service from the Data panel to a component, a corresponding project service is added. That particular project service and its associated parameters are auto-highlighted in the Data panel. So if multiple components exist and when you select a specific component, only those services which have been added to that component are highlighted in the Project Services of the Data panel. The Data panel also allows you to view the mappings for each project service operation in the component. The onMapping Event of the operations in the component is not generated separately in the CodeGen. You can view the onMapping Event in the preShow Event of the component
Note: Currently, only the Details form and List form UI are supported for the drag and drop of services into a component; Entry form UI is not supported.
If the sample service that you are trying to add to a component has already been added to another component, a Conflict window appears. In such a scenario, you must perform any one of the following actions to resolve this issue:
This section contains the following topics:
Create a component and leverage sample services from the Data panel. You can bundle these services to the required widgets of a component. You can directly drag and drop services into a component and customize it according to your requirement.
In this scenario, we will xthe List-Details (Employee) component from Kony Marketplace and add services to the widgets of the component. You can add parameters (for example, Name) to specific widgets (for example, empname Label) of the component. This component contains the following two screens:
To import the List-Details (Employee) component and add services to the component, follow these steps:
The parameters are mapped to the corresponding component widgets, and the services are created in your Kony Fabric instance. In addition, the mappings are highlighted and displayed under Project Services on the Data panel.
Users can import the component with bundled services that you published on Kony Marketplace. They can then modify the component as per their requirement.
Consider a scenario where Valerie (a user who wants to create a CRM app) imports your Employee List-Detail component to Kony Visualizer. However, she does not want to view employee data. Instead, Valerie wants to view the data of her customers. She can use the Data Panel support for Components feature to map data from another service that fetches customer data to the widgets, wherever required. Valerie can leverage an Object service to fetch the data, and she can directly map the response parameters from the Data panel.
Valerie can follow these steps to import the Employee List-detail component from Kony Marketplace and customize the services bundled with it:
A target container is a Container widget that can contain other child widgets. To specify a Container widget as a target container, set both its Expose Widget and Set As Target Container properties to On.
To specify a Container widget as a target container:
Note: If the Expose Widget property is set to Off, setting the Set As Target Container property to On will set both the Expose Widget and Set As Target Container properties to On.
Kony Visualizer displays the Placeholder property. The Placeholder property lets you specify further information or direction to a user; for example "Add Content Here" or "Drop Image Here."
In addition to specifying which of a component's widgets to expose to users, you can specify the skins to expose.
To expose a component's skins:
To prevent your component from being modified by users, you can lock the component. Users will not be able to view or modify the component's source code.
To lock a component:
Once you create a component with a contract, you can specify which properties of the component to expose to users. The specified properties are called pass-through properties. You can also define custom properties.
To manage properties of a component with a contract:
Click the plus sign (+) for each pass-through property you want to define. Click the delete symbol (X) to delete an existing property. To define a new pass-through property, specify the following for each property:
Click Apply to add the pass-through property.
Note: You can also designate a widget's property as a pass-through property by navigating to the widget and right-clicking on the property name.
Click the plus sign (+) for each custom property you want to define. Click the delete symbol (X) to delete an existing property. To define a new custom property, specify the following for each property:
Click Apply to add the custom property.
Important: Unlike a pass-through property, which is based on an existing property of the component, a custom property has no built-in behavior. You must define the property's behavior programmatically. On the Templates tab, expand the component's Modules node, open the controller module, and add code defining the property's behavior to the controller code. For more information, see Define the Behavior of a Custom Property, Event, or Method in Code.
In addition to specifying pass-through properties, you can specify which of the component's events to expose to users. You can also define custom events.
To manage events of a component with a contract:
Click the plus sign (+) for each pass-through event you want to define. To delete an existing event, select the event and click the delete symbol (X). To define a new pass-through event, specify the following for each event:
Click Apply to add the pass through event. Kony Visualizer adds the event to the Pass Through section of the Properties pane's Action tab.
Note: You can also designate a widget's event as a pass-through event by navigating to the widget and right-clicking on the event name.
Click the plus sign (+) for each custom event you want to define. Click the delete symbol (X) to delete an existing event. To define a new custom event, specify the following for each event:
To add parameters to the custom event, click the Manage Events button, and specify the parameter information in the dialog box.
Click Apply to add the custom event. Kony Visualizer adds the event to the Custom section of the Properties pane's Action tab.
Important: Unlike a pass-through event, which is based on an existing event of the component, a custom event has no built-in behavior. You must define the event's behavior programmatically. On the Templates tab, expand the component's Modules node, open the controller module, and add code defining the event's behavior to the controller code. For more information, see Define the Behavior of a Custom Property, Event, or Method in Code.
In addition to specifying pass through properties and events, you can specify which of the component's methods to expose to users. You can also define custom methods.
To manage methods of a component with a contract:
Click the plus sign (+) for each pass-through method you want to define. Click the delete symbol (X) to delete an existing method. To define a new pass-through method, specify the following for each method:
Click Apply to add the pass-through method.
Click the plus sign (+) for each custom method you want to define. Click the delete symbol (X) to delete an existing method. To define a new custom method, specify the following for each method:
To add parameters to the custom method, click the Manage Methods button, and specify the parameter information in the dialog box.
Click Apply to add the custom method.
Important: Unlike a pass-through method, which is based on an existing method of the component, a custom method has no built-in behavior. You must define the method's behavior programmatically. On the Templates tab, expand the component's Modules node, open the controller module, and add code defining the method's behavior to the controller code. For more information, see Define the Behavior of a Custom Property, Event, or Method in Code.
When you define pass-through or custom properties, events, and methods for a component, you can specify how they are displayed in the Properties pane by organizing them in groups.
For example, you can specify that two custom properties are displayed in a group under the heading, "General," and that a third property is displayed under the heading "Special" by defining them as follows in the Manage Properties dialog box.
The properties will be displayed in the Properties pane.
You can also group both pass-through and custom properties under the same heading. For example, the following General properties of the Rating Prompt component include a mixture of pass-through and custom properties:
To group properties of a component with a contract:
If the group name does not exist, click in the Group field, select Manage Group to open the Manage Groups dialog box, and then add the group name.
To group events of a component with a contract:
If the group name does not exist, click in the Group field, select Manage Group to open the Manage Groups dialog box, and then add the group name.
To group methods of a component with a contract:
If the group name does not exist, click in the Group field, select Manage Group to open the Manage Groups dialog box, and then add the group name.
When you create a component with a contract, you can define pass-through and custom properties, events, and methods for the component. Defining pass-through properties, events, and methods does not require that you write code. You simply specify the built-in properties, events, and methods that you want to expose. However, a custom property, event, or method does not have any built-in behavior. You must define its behavior in code.
First, specify a name for the custom property, event, or method using the Manage Properties dialog box. For a custom property, you can also specify a display name, data type, and default value, and whether the property is read-only or read-write. If the property has a list selector, you can specify the key value pairs that make up the list. For more information on working with the Manage Properties dialog box, see Manage Properties of a Component with a Contract, Manage Events of a Component with a Contract, or Manage Methods of a Component with a Contract.
Once you specify information in the Manage Properties dialog box, you can add code to the component's controller module to define the behavior of the custom property, event, or method.
To define the behavior of a custom property, event, or method in code (Beta):
For example, the following code defines custom properties for the Login component, which can be downloaded from Kony Marketplace.
/** * @function initGettersSetters * @description contains getters/setters for the usernameMinimumChar and usernameValidationMsg custom properties */ initGettersSetters: function() { defineGetter(this, "usernameMinimumChar", function() { konymp.logger.trace("----------Entering usernameMinimumCharacter Getter---------", konymp.logger.FUNCTION_ENTRY); return this._usernameMinimumChar; }); defineSetter(this, "usernameMinimumChar", function(val) { konymp.logger.trace("----------Entering usernameMinimumCharacter Setter---------", konymp.logger.FUNCTION_ENTRY); try { if (val == null || val == undefined) { konymp.logger.warn("Username Min Char is undefined"); throw { "Error": "LoginComponent", "message": "Username Min Char is undefined" }; } if (isNaN(val)) { konymp.logger.warn("Invalid datatype for Username Min Characters Property"); throw { "Error": "LoginComponent", "message": "Invalid datatype for Username Min Characters Property" }; } if (this.usernameMaxChar & amp; lt; val) { konymp.logger.warn("usernameMaxChar is less than usernameMinimumChar"); throw { "Error": "LoginComponent", "message": "username Max Char is less than Username Min Character propert" }; } this._usernameMinimumChar = val; } catch (exception) { if (exception["Error"] === "LoginComponent") alert(JSON.stringify(exception)); } }); defineGetter(this, "usernameValidationMsg", function() { konymp.logger.trace("----------Entering usernameValidationMsg Getter---------", konymp.logger.FUNCTION_ENTRY); return this._usernameValidationMsg; }); defineSetter(this, "usernameValidationMsg", function(val) { konymp.logger.trace("----------Entering usernameValidationMsg Setter---------", konymp.logger.FUNCTION_ENTRY); this._usernameValidationMsg = val; }); }
Creating and using a Custom Event involves three stages, creating a custom event, invoking the custom event, and consuming the custom event.
To create, consume, and invoke a custom event, do the following:
alert(“Yay! Custom event”);
Rev | Author | Edits |
8.0 | SHS | SHS |
Copyright © 2013 Kony, Inc. All rights reserved. |