Tuesday, January 19, 2010

GWT vs. Grails

Both Google Web Toolkit (GWT) and Grails have been in the public domain for about two years now. I admit that my knowledge of, and experience with, both is very recent. When I started to investigate each technology I was very excited about the possibilities, namely:
  • Groovy and Grails provides the rapid-prototyping inherent with "convention-over-configuration"
  • Grails, being a Java framework, fits perfectly with legacy or yet-to-be-introduced Java technologies
  • GWT provides the tools for developing Rich Internet [client] Applications (RIA)
  • GWT, being based on Java, is Google's version of "write-once-run-on-any-browser"
After having spent merely a week on each technology, what follows in this entry is my interpretation and reaction of the above claims and discovery of the "buts..." hidden in the cracks.
First, I found all of the above claims to be true. Second, while both have client-side and server-side capabilities, Grails is the clear winner on the server side while GWT is a marginal winner on the client side. Third, if you want to use GWT and Grails together, the process can be cumbersome but it does work. Let me explain.
Grails:
  • The Object-Relational Mapping, which is based on Hibernate, is absolutely fantastic.
  • Scaffolding is even better than Ruby on Rails IMO because you can combine scaffolding with custom code. If anyone reading this can tell me otherwise about RoR, please feel free to comment politely.
  • Many operations, such as returning a list of objects in JSON format are one or two lines of code.
  • The generated controllers and views are still heavy on the "client-request/server-response" paradigm. A developer wanting to employ AJAX to develop a RIA still needs to install third-party JavaScript libraries and write framework code.
  • The suggested MVC structure doesn't [easily] encourage digressing from the Domain Class structure. For example, you're encouraged to edit a Task on the Task/edit page. However, RIA's are trending towards multi-faceted documents (think iGoogle home page) where a user interacts with diverse information on a single page.
GWT:
  • Creating Web pages by writing Java and compiling for all supported browsers brings RIA GUI creation to the Java purist and reduces testing overhead.
  • Developing a simple, self-contained (i.e., client-only) UI is easy and fun.
  • The Same Origin Policy (SOP) makes rapid development virtually impossible unless you try any of these methods:

    1. Compile your GWT application then copy to the Application server running your database services. If you do a lot of write-test-write-test, this simply is not a solution.
    2. Go through a complex procedure to "get around" the SOP, which only works for GETs. If you want to test UPDATE or INSERT you still need to find a better way.
    3. Develop a complete set of servlets to mimic your backend services.
    4. Use the GWT plug-in for Grails

  • While very powerful indeed, writing AJAX calls using GWT is far more complex than simply writing them in JavaScript.
You can probably sense the theme: Grails is easier to get up and running, but lacks sophisticated UI tools. GWT can do really neat things on the client side if you're willing to invest the time. Mixing the two is possible using the "official" way to integrate the two.

The caveat is that the GWT plug-in for Grails appears to be buggy if you compile and invoke from within Eclipse.  That means you should keep a terminal open for "grails run-app", a terminal for "grails run-gwt-client", and Eclipse.

Any other method doesn't really work very well.

5 comments:

  1. Hi,

    Just my 2 cents...
    i'm currently playing with grails 1.2 + gwt 2.
    I'm working in IDEA and have no trouble with gwt plugin: just run grails and gwt hosted (within idea)

    One important thing is that officially gwt plugin for gwt 2.0 is not availible yet, but you may install the snapshot (author says its pre-final version now): grails install-plugin gwt 1.5-SNAPSHOT

    Here is some example projects for gwt-plugin: http://www.google.com/url?sa=D&q=http://github.com/pledbrook/grails-gwt/tree/master/test/projects/&usg=AFQjCNEIpClrb5EFP65TO_2k3awBDi2k5g

    And the last thing to note is sample of SmartGWT integration: http://code.google.com/p/grails-gwt-smart/wiki/GettingStarted

    ReplyDelete
  2. Hi mate, your analysis where you say one must compile and copy the generated files to the server to do what you describe as write-test-write-test cycle is completely wrong. I suggest that you spend sometime as given the 2.0 release uses a regular browser there is absolutely no need for the procedure you describe. Even the old pre 2.0 GWT supported connecting to any server of your choice and still have the capability to debug your GWT app.

    ReplyDelete
  3. Grails doesn't have a good Eclipse Plugin, that is just the reason why I discarded it.

    I have tryed using Grails on Netbeans and Idea, but none of it is remotely near Eclipse. I feel like programming with djgpp.

    ReplyDelete
  4. Doesn't have an eclipse plugin? Who needs an IDE with Grails? I like eclipse and have used it for years, but let's face it, a really good editor is all you need for Grails.

    Ween yourself off, you'll feel better about it.

    ReplyDelete
  5. "While very powerful indeed, writing AJAX calls using GWT is far more complex than simply writing them in JavaScript."

    What? You seem to be missing the point here... which is to NOT write javascript. By coding only in Java you have all the benefits of a strong typed language, with amazing tools and debugging.

    I too hate the Java verbosity, but for large scale applications the maintainability of a javascript app is just horrible.

    ReplyDelete