Miles to go ...

Arun Gupta is a Technology Evangelist for Web Services and Web 2.0 Apps at Sun. He was the spec lead for APIs in the Java platform, committer in multiple Open Source projects, participated in standard bodies and contributed to Java EE and SE releases.
« GlassFish Book Revie... | Main | GlassFish @ Bangalor... »

http://blogs.sun.com/arungupta/date/20071212 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");

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

component.css

.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:

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
HINT_templates.hello=<html>Hello</html>

widget.json

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

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

Bundle.properties
resources
  hello
    component.htm
    component.js
    component.css
    widget.json (optional)
templates
   hello
     hello.jsp
     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 ...

  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 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

del.icio.us | furl | simpy | slashdot | technorati | digg
Comments:

[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...

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 #

[Trackback] Bookmarked your post over at Blog Bookmarker.com!

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 #

Post a Comment:
  • HTML Syntax: NOT allowed
« GlassFish Book Revie... | Main | GlassFish @ Bangalor... »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.

--> ajax ajaxworld conf eclipse fitness gem glassfish glassfishday hyderabad india indigo interoperability javaone javaone2008 jax-ws jmaki jpa jruby mac marathon metro microsoft mysql netbeans phobos photography presos railsconf ruby rubyonrails running runninglog runsfm screencast siliconvalleymarathon sun suntechdays swdp tango theserverside totd training traveltips v3 vista wcf web2.0 webservices webtier windows wsaddressing wsit youtube
Locations of visitors to this page

calendar

« September 2008
SunMonTueWedThuFriSat
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today
www.flickr.com
This is a Flickr badge showing public photos from ArunGupta. Make your own badge here.
Add to Technorati Favorites

Last 50