Create Weblets
You can create a Weblet to provide access to data and functionality on a Web site, and to customize the user interface.
You use the GenericWebPart Web part to add the weblet to a Web part page and you use properties to modify the weblet. For more information, see Create Web Part Pages.
-
Add a class to the Application Object Tree (AOT) that extends the WebAppWebLet class. For more information about adding a class, see Declaration of Classes.
-
To override one or more methods, right-click the class, click Override Method, and then click a method name.
-
Override the Run method to add the business logic for the weblet. The Run method outputs HTML.
Note If you override the Run method to perform database updates, confirm that the request to perform the action is valid by calling the WebSession.isPostSafe method. This helps prevent the execution of malicious code.
-
To add weblet properties, override the createProperties method and call the addProp method. You can call the propAttribute method to assign an attribute to a property. You can call the setProp method to change the value of an existing property.
In the following example, the addProp method adds the WebHeight, WebWidth, Favorites, and FieldGroupName properties, which are extended data types. The extendedtypestr intrinsic function converts the extended data type name to a string.
The default value for the Favorites property is Yes from the NoYes enum. The default value for the FieldGroupName is WebCategoryBrowsing.
The propAttribute method specifies that the WebWidth and WebHeight methods are hidden.
The setProp method changes the value of the WebletName property by using the classstr intrinsic function.
void createProperties() { super(); this.addProp(extendedtypestr(WebHeight),0); this.propAttribute(extendedtypestr(WebHeight),'Hidden',true); this.addProp(extendedtypestr(WebWidth),0); this.propAttribute(extendedtypestr(WebWidth),'Hidden',true); this.addProp(extendedtypestr(Favorites),NoYes::Yes); this.addProp(extendedtypestr(FieldGroupName),'WebCategoryBrowsing'); this.setProp(extendedtypestr(WebletName),classstr(WebCatBrowseWeblet)); }For more information about intrinsic functions, see Intrinsic Functions. For more information about configuring extended data types to use enum values, see Extended data type properties.
-
Override additional methods as needed.
-
Click Web, right-click Weblets, and then click New Weblet Item.
-
Right-click the weblet item, click Properties, and then select the class that you added in step 1 from the Object property list.
The weblet appears in the WebletItem property list for the GenericWebPart Web part.