Skip to main content

jMaki publish/subscribe and debugging

Posted by arungupta on May 21, 2007 at 11:37 AM PDT

So far you've been playing with jMaki and
created some Web
and/or href="">Rails
applications. Let's say you've gone a step ahead and some
widgets in your application use jMaki's href="">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 href="">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:


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

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
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
applications can be WARed
and then deployed on GlassFish.



Related Topics >>