Skip to main content

jMaki in Phobos

Posted by robc on August 17, 2006 at 7:04 PM PDT

There's been quite a bit of activity on Project Phobos recently. A notable highlight is that jMaki is now fully integrated with Phobos, ready to serve your AJAX needs.

jMaki offers a uniform interface to an ever-expanding set of AJAX components. When writing JSP and JSF components, jMaki appears as a tag library. For example, this JSP snippet inserts a Yahoo Map widget into the page:

<a:ajax name="yahoo.map"
        args="{centerLat:37.39316,centerLon:-121.947333700,
               mapType:'YAHOO_MAP_SAT', width:600}"/>

Since widgets run in the browser, you won't be surprised in seeing a JavaScript object literal passed as an argument. In the case of a Yahoo Map widget, it contains things like the latitude and longitude of the desired location. Note though that this "object" is enclosed in quotes, as necessary for an HTML attribute.

In Phobos, JavaScript is used on both client and server, and jMaki is exposed via a built-in library, library.jmaki. Here's the Phobos equivalent of the previous code snippet:

<% library.jmaki.insert({component: "yahoo.map",
                         args: {centerLat:37.39316,
                                centerLon:-121.947333700,
                                mapType:'YAHOO_MAP_SAT',
                                width:600}}); %>

As you can see, here the arguments are really an object, not a string, so you can programmatically construct complex arguments with great ease. The jMaki library in Phobos takes care of serializing them to JSON right before inserting their literal representation into the page. And of course, just like the jMaki JSP tag library, library.jmaki.insert takes care of loading all the necessary scripts into the page and instantiating the component, relieving developers from a lot of bookkeeping.

Until recently, Phobos used to package its own version of the Dojo Toolkit, but as a side-effect of the integration with jMaki, it now relies on the version that comes with the latter. This is not entirely pain-free, since existing applications will need to change their references to Dojo to point to the new location, /static/resources/libs/dojo/dojo.js. On the plus side, from now on Phobos will use the latest and greatest (and most tested) version of Dojo as validated by jMaki use. Moreover, Phobos now shares with jMaki a common directory layout for AJAX components and libraries, as well as all the configuration information. This means that a web application can include just one copy of jMaki and use it in a straightforward way from JSP, JSF and Phobos, without any configuration nightmares.

For more information and a quick tutorial on using jMaki with Phobos, see Jennifer's blog entry on the subject. Also, keep an eye on the Phobos web site, as we'll be posting more information there soon.

Related Topics >>