jMaki on Rails
By craigmcc on May 07, 2007
Yes, it's me again. I really am alive, but have been heads down learning new technologies. You see, my latest role is as architect around Web 2.0 (or next generation web) development as it relates to Sun's tools. That being said, I have watched with interest the rapidly improving JRuby implementation of the Ruby language, and growing market success of the Ruby on Rails framework. It was time to learn a little bit of Ruby (along with other dynamic languages), and a larger bit of Rails, to understand what was going on outside the world of languages that begin with "J" and end with "a". After all, I have been preaching about the wider world inside the halls of Sun ... it was time to get down and dirty with some real code.
Initially, I was a bit of a skeptic, being very happy in my "strongly typed" comfort zone. Yet, I discovered what many other Java developers have discovered about Rails -- it really can make developing web applications more fun. More on that in the future.
jMaki On Rails
During the same time frame, I started following the jMaki project (and its spinoff widget libraries project) more closely. It became clear that the conceptual approaches taken by jMaki and Rails were very much compatible with each other. For example, here's an RHTML view containing a Yahoo Menu widget:
Of course, you can pass information from your Rails controller to jMaki, just like you can with all the other helper methods, via instance variables created by your action methods. For example, if you had built up a hash named
@model_data that contained all the information currently included literally in the view above, you would end up with something much simpler:
<%= jmaki_widget "yahoo.map", @menu_data %>
Hybrid approaches, with data partially included in the view and partially provided by the model, are available as well. A common use case for this would be in a table or data grid control, where you might specify the column headings in the view and pull the row data from the model. Any combination is possible, given that the second and subsequent arguments are all just Ruby expressions.
Using jMaki On Rails
Support for jMaki is still pretty bleeding edge, but will make its way towards a fully functional release in the next few months. If you want to play with it today, start by grabbing either Ruby or JRuby, and also installing Rails (1.2.x or later) and a Subversion client. The jMaki support is provided as a set of Rails plugins ... one for the core runtime, and one for each widget library you want to support.
Let's create a Rails application, and then load jMaki support for both Yahoo and Spry widgets. In this case I am adding the jMaki plugins repository to my local configuration -- that is optional, but makes the install commands easier to perform.
rails jmaki_demo cd jmaki_demo script/plugin source http://jmaki-goodies.googlecode.com/svn/trunk/rails_plugins script/plugin install jmaki_core script/plugin install jmaki_spry script/plugin install jmaki_yahoo
At this point, my Rails application is fully jMaki-enabled. In the
<head> section every page, we will need to establish the jMaki environment for that page (typically, you will do this in a layout to avoid repeating yourself):
Finally, individual jMaki widgets are created by using the
jMaki On Rails On NetBeans
To use this, you will also need the latest Ruby support in NetBeans, which is available in the NetBeans 6.0 Milestone 9 preview.
The current code is pretty rough, and many of the widgets are not fully functional yet. But the hard part of the problems have been solved, and we're down to the details. There are lots of things that need to changed, but here are two bugs and a missing feature that are the most visible problems at the moment:
- The current runtime for Rails does not yet understand the jMaki conventions for passing API keys for things like Google Maps down to the widget.