Miles to go …

December 12, 2007

TOTD #20: How to create a new jMaki widget ?

Filed under: netbeans, totd, web2.0 — arungupta @ 11:26 am

This TOTD explains how to create a new jMaki widget and make it available in the NetBeans palette.

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.


<div id="${uuid}" class="hello"></div>



jmaki.widgets.hello.Widget = function(wargs) {
  var hello = document.getElementById(wargs.uuid);
  hello.innerHTML = "Hello " +;


.hello {
  font-size: 22px;color: red;

The following files are required if you like to package your component as a reusable widget library in the NetBeans IDE:


<a:widget name="hello" args="{name: 'Duke'}" /> (top-level)

jMaki.Library.Name=jMaki Hello Widget (templates)



  'name': 'Hello',
  'type': 'custom',
  'version': '1.0',
  'jMakiVersion': '1.0'

Package these files together in the following directory structure (choose any zip file name):
    widget.json (optional)

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 …

  1. Templates for other languages such as Ruby or PHP can be added in the templates directory. This enables drag-and-drop of your widget in those languages as well.
  2. It’s important to maintain the case sensitivity of the property names in otherwise 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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget
  2. TOTD #5: Loading data from beans in jMaki widgets
  3. TOTD #15: Delete/Update Row from Database using jMaki Data Table
  4. jMaki – Accessing External Services
  5. jMaki publish/subscribe and debugging


  1. [Trackback] I presented on GlassFish and related technologies (Metro, JRuby-on-GlassFish and jMaki) at the Department of Computer Science, Delhi University last week. The slides are available here.The talk was very well attended with approximately 120 students an…

    Comment by Arun Gupta's Blog — December 14, 2007 @ 7:20 am

  2. Arun, TOTD request (I’ve been trying to do this for a long time without success): Given a simple Mavenized Java project (say a program that just outputs "Hello World!"), how can I debug it (trace the running source code) within Netbeans 6.0? When the user opens a Mavenized project, NetBeans’ built-in Mevenide (sic) plugin detects the pom.xml in the Maven project and loads it automatically as a Maven project within the NB. But it seems to provide no ability to debug the Java class within the IDE. (Normal Java projects debug without difficulty.)

    Comment by Glen — December 15, 2007 @ 6:13 pm

  3. "…does not define any jMaki components. Check to make sure that it is packaged correctly." — protested by Netbeans 6.0 when I tried to add this example hello widget.

    I followed your directory structure but not succeed. Frustrated.

    What is the exact specification for the file widget.json and for the package structure?


    Comment by wc — December 30, 2007 @ 10:01 pm

  4. [Trackback] Bookmarked your post over at Blog!

    Comment by exact — December 31, 2007 @ 4:58 am

  5. wc, widget.json is optional. The directory structure had an additional directory at the top-level. Now I cleaned it up. Also added the structure for widget.json.

    Please try and let me know.

    Comment by Arun Gupta — January 1, 2008 @ 6:10 pm

  6. Hi Arun,

    I have started using jMaki in our project. We have started to develop jmaki widgets.

    I tried to add our widget as part of eclipse plugin but was not successful.

    How shall I proceed after creating zip file with appropriate content of widgets


    Comment by siva — March 10, 2008 @ 12:13 pm

  7. Hi, Arun,
    I used Netbeans build 2 project.
    First project is RestfulWebservice (jmakiDB) and next is Jmaki Project I used Restful Webservice client Stubs. In glue.js why I can’t use event ==> jmaki.subscribe("*onSelect", function(args) {
    jmaki.log("glue.js : onSelect request from: " + args.widgetId);
    jmaki.doAjax({method: "POST",
    url: "http://localhost:8080/jmakiDB/resources/employees/1/",
    callback: function(req) {


    url:"http://localhost:8080/jmakiDB/resources/employees/1/&quot; is restful. Please how i can do or idea for fix this problem.
    Thank you very much.

    Comment by Suphat — April 1, 2008 @ 2:28 am

  8. Suphat, Look for a complete application using jMaki and RESTful endpoints at:

    Please post your jMaki related questions at jMaki forum:

    Comment by Arun Gupta — April 1, 2008 @ 8:41 pm

  9. yah

    Comment by Anonymous — April 5, 2008 @ 3:14 am

  10. I have started using jMaki in our project. We have started to develop jmaki widgets.

    I tried to add our widget as part of eclipse plugin but was not successful.

    Comment by BATTERY — November 27, 2008 @ 5:24 pm

  11. Have you tried the following screencast:


    Comment by Arun Gupta — November 28, 2008 @ 6:59 am

  12. 专业销售各种<a href=;望远镜&lt;/a&gt;,&lt;a href=;军用望远镜&lt;/a&gt;,&lt;a href=;天文望远镜&lt;/a&gt;.货到付款。网址

    Comment by actuer — February 13, 2009 @ 8:48 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress