Skip navigation

If you are looking for a simple, easy to use and configure web framework for Java, Grails is the way to go.  I spent a ton of time looking around for Java web frameworks and I landed on Grails.  I am in the process of rebuilding my company’s public facing website as well as their intranet.  Because the two sites need access to the same data, I decided to build a common class library which handles all data access.  Although Grails is meant to handle all mapping and data acess for you, it was pretty easy to work in my existing data access project.

The first thing I would like to note about Grails is that there is virtually no configuration.  You will have to edit one or two configuration files if you want to customize certain aspects of the application, but unlike other frameworks, there is ZERO xml configuration.  I have run into a number of challenges as my website, like all websites, has a bunch of unique features.  Due to the excellent documentation for Grails I have had little to no trouble overcoming these challenges.

Because my application uses it’s own set of class factories, I was not able to simply drop my hibernate.xml.cfg and mapping files into grails.  I need to have complete control over how the objects are loaded and saved to the database.  This meant I would need something similar to the OpenSessionInViewFilter.  The problem with adding a fitler is that I didn’t want to open up sessions for every request, just requests that needed acess to the data.  After reading through the documentation I found that Grails has support for controller filters, here is a simple way to open up and close sessions for Hibernate in a grails filter.  Drop a file named HibernateFilters.groovy into the grails-app/conf directory:

public class HibernateFilters {
def filters = {
ensureSession(controller:’*’, action:’*’) {
before = {
HibernateUtil.getCurrentSession().beginTransaction();
}

afterView = {
HibernateUtil.getCurrentSession().getTransaction().commit();
}
}
}
}

Between tag libraries, templates and layouts, building UI in a Grails application is a breeze.  The UI code is so clean because of the way the rendering engine works.  There is no need for server side code in the views (although it is possible to put it there).

AJAX support is excellent in Grails.  It solves the common problem of rendering of UI on the server side as well as the client side.  It is simple to render a template or view and return it in an AJAX call.  This is huge, becuase you won’t find yourself writing the same UI code twice.  In my experience with .NET this was one of the most frustrating parts of building AJAX applications.  Also, Grails makes it really simple to render JSON and XML.  You can simply use “as JSON” or “as XML” in your render calls.

All in all, Grails is a quick and easy to use framework that provides all the tools a web developer needs to build a rich and dynamic web application with minimal headaches.  Out of the frameworks I’ve used (ASP.NET, CakePHP, Wicket, Tapestry), Grails is definitely at the top of the list (followed closely by CakePHP).

Check out the official grails website.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: