jMaki publish/subscribe and debugging

So far you've been playing with jMaki and created some Web and/or Rails applications. Let's say you've gone a step ahead and some widgets in your application use jMaki's publish/subscribe mechanism to talk with each other. Some jMaki widgets, such as Menu and Dynamic Container are pre-configured to publish and subscribe to the same topic. So if you develop a simple menu-based application then it'll work without adding any glue code. Another example is Yahoo GeoCoder publishing and Yahoo Maps and Google Maps subscribing. This allows you to drop all three widgets together on the same page and if you enter a city and state in GeoCoder, the coordinates will show up in both the maps. So far so good, but what if you are writing custom publish and subscribe code and it's not working. Lets see how we can debug that.

Let's say there is a Yahoo Calendar and Data Table widget in the page. The Data Table displays stock tickers by pulling the data from quote servers for the current date. You'd like to modify the application such that whenever a date is selected in the Calendar widget, the Data Table refreshes itself by pulling quotes for that date.

The Calendar widget already publishes an event to "/yahoo/calendar/onSelect" topic. All you need to do is modify 'component.js' in Web pages, resources, yahoo, dataTable subtree and listen to that topic. For that, you add the following statement:

jmaki.subscribe("/yahoo/calendar/onSelect", calendarListener);

on line 172 of 'component.js'. The 'calendarListener' function is defined as:

function calendarListener(item) {
    var targetDiv = document.getElementById("newpage");
    targetDiv.innerHTML = item.value;
}

On 'index.jsp', where both the widgets live together, a new <div> is added:

<div id="newpage"></div>

Now any date selected in the calendar is printed on the page. The 'calendarListener' function can be easily modified such that the dataTable is refreshed after processing the date.

We created a simple, yet powerful example, demonstrating jMaki publish/subscribe mechanism.

The mechanism is simple so it should just work even if there are custom widgets and they publish events to their own topic. But this is software so in all likelihood don't be surprised if it does not :) But jMaki at least provide a way to debug that situation. Open 'Web pages', 'resources', 'jmaki.js'. Search for 'this.debugGlue=false;this.debug=false;' in this file. Change the 'false' to 'true' and save the file. After you refresh your application in the browser window, the bottom-right portion of your browser window shows all the topics and messages published on it as shown below:

Happy debugging!

All jMaki Web applications can be deployed on GlassFish or Rails applications can be WARed and then deployed on GlassFish.

Technorati: jmaki glassfish rails rubyonrails

Comments:

[Trackback] A jMaki widget in a page can communicate with: Other widgets on the same page using publish/subscribe mechanism Services in the application domain using service=&quot;data.jsp&quot;. Services outside the application domain using proxy (xhp). This blog ...

Posted by Arun Gupta's Blog on July 27, 2007 at 03:13 AM PDT #

[Trackback] jMaki is a light-weight framework for build Web 2.0 applications. It provides support for multiple languages - Java (1, 2, 3, 4, 5, 6) , PHP, Ruby (1, 2), Phobos (1). The numbers in parentheses indicate the entries that I've...

Posted by Arun Gupta's Blog on August 23, 2007 at 11:08 PM PDT #

[Trackback] ...

Posted by Arun Gupta's Blog on September 11, 2007 at 12:35 AM PDT #

how to create our own widgets using jmaki

Posted by sreenivaulu on August 31, 2010 at 03:41 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
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