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 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. - It’s important to maintain the case sensitivity of the property names in
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
Related posts:
[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
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
"…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
Comment by wc — December 30, 2007 @ 10:01 pm
[Trackback] Bookmarked your post over at Blog Bookmarker.com!
Comment by exact — December 31, 2007 @ 4:58 am
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
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
Comment by siva — March 10, 2008 @ 12:13 pm
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.
Comment by Suphat — April 1, 2008 @ 2:28 am
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
Comment by Arun Gupta — April 1, 2008 @ 8:41 pm
yah
Comment by Anonymous — April 5, 2008 @ 3:14 am
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
Have you tried the following screencast:
http://blogs.sun.com/arungupta/entry/jmaki_in_eclipse
?
Comment by Arun Gupta — November 28, 2008 @ 6:59 am
专业销售各种<a href=http://www.531shop.net>望远镜</a>,<a href=http://www.531shop.net>军用望远镜</a>,<a href=http://www.531shop.net>天文望远镜</a>.货到付款。网址 http://www.531shop.net
Comment by actuer — February 13, 2009 @ 8:48 pm