Wednesday December 12, 2007
TOTD #20: How to create a new jMaki widget ?
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.
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 directory. This enables drag-and-drop of your widget
in those languages as well.Bundle.properties 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
Posted by Arun Gupta in web2.0 | Comments[9]
|
|
|
|
Posted by Arun Gupta's Blog on December 14, 2007 at 07:20 AM PST #
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.)
Posted by Glen on December 15, 2007 at 06:13 PM PST #
"...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?
Thanks
Posted by wc on December 30, 2007 at 10:01 PM PST #
Posted by exact on December 31, 2007 at 04:58 AM PST #
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.
Posted by Arun Gupta on January 01, 2008 at 06:10 PM PST #
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
Thanks
siva
Posted by siva on March 10, 2008 at 12:13 PM PDT #
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) {
//el
}
});
});
url:"http://localhost:8080/jmakiDB/resources/employees/1/" is restful. Please how i can do or idea for fix this problem.
Thank you very much.
Posted by Suphat on April 01, 2008 at 02:28 AM PDT #
Suphat, Look for a complete application using jMaki and RESTful endpoints at:
http://blogs.sun.com/arungupta/entry/screencast_web11_travel_map_another
Please post your jMaki related questions at jMaki forum:
http://forums.java.net/jive/forum.jspa?forumID=96
Posted by Arun Gupta on April 01, 2008 at 08:41 PM PDT #
yah
Posted by 71.96.142.107 on April 05, 2008 at 03:14 AM PDT #