jMaki publish/subscribe and debugging
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
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 700 reads





