TOTD #20: How to create a new jMaki widget ?
In order to create a jMaki widget, it's important to understand the jMaki Widget Model.
![]() |
Basically, "component.htm", "component.js" and an optional "component.css" together make a jMaki widget. |
Here are the files for a Hello World widget that takes an argument, concatenates it with the string "Hello" and displays the result on the page.
component.htm
<div id="${uuid}" class="hello"></div> |
component.js
jmaki.namespace("jmaki.widgets.hello"); |
component.css
.hello { |
The following files are required if you like to package your component as a reusable widget library in the NetBeans IDE:
hello.jsp
<a:widget name="hello" args="{name: 'Duke'}"
/> |
Bundle.properties (top-level)
jMaki.Library.Name=jMaki Hello Widget |
Bundle.properties (templates)
NAME_templates.hello=Hello |
widget.json
{ |
Package these files together in the following directory structure (choose any zip file name):
Bundle.properties |
And then you zip up these files together, that's it! Now this zip file can be added to the jMaki palette in the NetBeans IDE as shown here. Really simple!
After the widget is added to NetBeans palette, it looks like as shown below:

Now, just like any other jMaki widget, you can drag-and-drop "Hello"
from the jMaki palette in your JSP page and the following code fragment is
generated:
<a:widget name="hello" args="{name: 'Duke'}" />
After the application is deployed, the page is rendered in the browser as shown below:

Couple of points ...
- Templates for other languages such as Ruby or PHP can be added in the
templatesdirectory. This enables drag-and-drop of your widget in those languages as well. - It's important to maintain the case sensitivity of the property names in
Bundle.propertiesotherwise they will not be recognized.
Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.
Technorati: totd jmaki web2.0 widgets ajax netbeans
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 688 reads






