OpenAjax Alliance

OpenAjax Alliance News

Subscribe to OpenAjax Alliance News: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get OpenAjax Alliance News: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


OpenAjax Alliance Authors: Lori MacVittie, Chris Pollach, Yakov Fain, Maureen O'Gara, Elizabeth White

Related Topics: RIA Developer's Journal, ColdFusion on Ulitzer, Adobe AIR on Ulitzer, OpenAjax Alliance News, Open Source AJAX

Blog Feed Post

Bridging to Open Ajax

The Open Ajax Alliance is a standards organization with the mission of ensuring interoperability within Web based apps

And we wanted to use this textarea to write out certain events that we'd like to track. I could then have this code in a JavaScript file:

   1 var statusUpdate = function statusUpdate(name, data) {
   2     var statusArea = document.getElementById("statusArea");
   3     var text = statusArea.value;
   4     text = text + "Name: "+data.source.id;
   5     if (name === "jsf.event") {
   6         text = text +" Event: "+data.status+"\n";
   7     } else if (name === "jsf.error") {  
   8         text = text + " Error: "+data.status+"\n";
   9     }
  10     statusArea.value = text;
  11 };
  12 
  13 OpenAjax.hub.subscribe("jsf.event",statusUpdate);
  14 OpenAjax.hub.subscribe("jsf.error",statusUpdate);
In this case, we're subscribing to two channels - jsf.event and jsf.error, and calling the statusUpdate function when a message arrives on those channels.

So, where do those messages come from? Unlike JSF, the OpenAjax hub has a publish function, in addition to a subscribe function. By associating that publish function with a call to jsf.ajax.addOnEvent and jsf.ajax.addOnError, we can bridge between the two event systems - like this:

As I said, this is a somewhat specialized topic, but I thought it worth mentioning. The full code of the demo, including putting it into a component, is in Project Mojarra's source base, under the jsf-demo/OpenAjaxBridge directory.

   1 var openajaxbridge = {};
   2 
   3 openajaxbridge.eventUpdate = function eventUpdate(data) {
   4     OpenAjax.hub.publish("jsf.event", data);
   5 };
   6 
   7 openajaxbridge.errorUpdate = function errorUpdate(data) {
   8     OpenAjax.hub.publish("jsf.error",data);
   9 };
  10 
  11 jsf.ajax.addOnEvent(openajaxbridge.eventUpdate);
  12 jsf.ajax.addOnError(openajaxbridge.errorUpdate);

 <textarea id="statusArea" cols="40" rows="10" readonly="readonly" />

Read the original blog entry...

More Stories By Jim Driscoll

Jim Driscoll has worked at Sun Microsystems for 12 years, working on such projects as the first version of Servlets (in the Java Web Server), and the initial implementation of Java 2, Enterprise Edition. He is currently a Senior Engineer working on the implementation of Java Server Faces, helping to integrate technologies such as AJAX and Comet into the new release.