Stripes is the new Rails

July 11, 2006

I've have recently discovered Stripes, a Java web MVC framework. I know what you're thinking, yet another Java web framework? Struts, Webwork, Tapestry, Wicket, RIFE, do we really need another framework? I think the answer is yes. From my experiences with the Stripes framework, it seems like it has the simplicity and flexibility of Rails, without the limitations. What are the limitations of rails you ask? There are two that I can think of off hand:

  1. Indexed Properties

    It is very difficult to work with index and nested properties in Rails. In simple terms what I mean by indexed and nested properties is being able to have a form field called bugs[0].watchers[3].name, which means you have a list of bugs, and each bug has a list of watchers, and each watcher has a name, and you want to get/set the name property of bug #1, watcher #4 (the indexed are zero-based, like arrays). Stripes makes this easy, it seems to be much more difficult in Rails.

  2. Dealing with non-AR model objects

    Rails lacks the concept of a data binder. In Java, Spring MVC, Webwork and Stripes all have this. In the Java frameworks, if your form contains a field called user.firstname, it assumes you must have an object called user that has a property called firstname that you want to bind that value to. You bind the values to Plain Old Java Objects (POJOs), and they you can do whatever you want with the object.

    In Rails, the controller stores the request parameters into a data structure that is a Hash of Hashes, so the request parameter user[firstname] becomes { "user" => { "firstname" => "whatever" } }. Then, the base ActiveRecord class has a constructor that takes that hash as a parameter and sets the properties of the object based on the hash. But there are two problems with that. First, if your model objects don't subclass ActiveRecord, then you don't have that functionality. Second, if you have nested objects, it can't create them as necessary, you have to do that.

The Stripes framework is very easy to pickup and I found the author of the framework to be very helpful on the mailing list. Stripes gains most of its simplicity by relying on Annotations and conventions to limit the amount of configuration necessary. You only add a few things to your web.xml and then everything else is handled by annotations, there is no stripes.xml or whatever, as almost all other frameworks have.

I think there are a lot of similarities between Webwork and Stripes and I'm sure there will be even more similarities between Stripes and Struts 2.0, once it is available.

Posted in Technology | Tags Struts, Stripes, Ruby, Java, Rails, WebWork

Comments Disabled