Book review: Grails 1.1 Web Application Development
Z Jacek Laskowski - Wiki Projektanta Java EE
Grails 1.1 Web Application Development by Jon Dickinson, (Packt, May 2009)
When I first received the book I was pretty sceptical if I could learn anything from another book about Grails right after having read 3 before. What made me think it was worth giving it a try was that the author is a British and that the reviewers are a Java champion and PhD. Hence, even though I could probably not have learned a lot about Grails or Groovy themselves, I would at the very least have learnt a bit of English. It didn't take me long to find out how much I was mistaken. The book was different than the others I read as its main concern was to combine designing and developing an web application being a team communication portal with Grails/Groovy lessons. From the very beginning to its end it's clear that the idea to convey was not how to write another book about Grails with its foundation based on proven solutions like Groovy, Hibernate and Spring Framework covered, but for its simplicity to build a modern web application. Every chapter was about some part of the web application and how it was to implement it in Grails. I'd say it was about how to make your projects more agile and goal-oriented (which was to build a fully functional application) rather than to show how sexy your project could be right after introducing Grails. Every chapter started with some intro to the issues Grails developers would face when our web apps were of more use and their solutions. The author called us "the pragmatic user-centered people".
The book begun with presenting available projects and acronyms overwhelming Java newcomers (which certainly is the reason why so many say Java is tough). There's a place for Ruby on Rails, Hibernate, Spring Framework, Groovy and DSL. It's clear that we're approaching a moment in Java ecosystem lifecycle where having so many means one can still not find the one. At some point, the author mentioned about Stripes, but not Wicket or JBoss Seam, which I thought were better recognized as web application frameworks. It turned out that it was just at the final chapter where Wicket and Google Web Toolkit found their place in the book, but JBoss Seam didn't.
In the 2nd chapter I found a very interesting explanation about no package classes in Java and although I had known it's not a good practice to create ones I didn't know what the real issue was. Even after having read the Grails books earlier I didn't know that the names of the Groovy class properties were important and the scaffolding uses them to construct human-readable names for the views. It's clear now, but it had not been until I found it explained in this book. That's these gems which made the book worth its time. How many of us know that the scaffolding uses only 6 columns to build views? I didn't. The chapter 2 finished as early as it had started. It was quick and easy, perhaps too fast for Grails novices, but enough to let them create their first Grails webapp.
In the 3rd chapter I was pleasantly surprised when I had made a comment to myself about manual handling the lastUpdated and dateCreated properties after which came the author's comment that Grails takes care of it and we don't have to. Nice surprises come at a cost (of heart attacks or coffee on your keyboard). It was the time when one could read much about controllers, actions, views, taglibs, templates and models. With the explanation of the parameters of the dynamically-added save() method and the issue addressed by the redirect-after-save solution I knew I was learning Grails more and more. A couple of words about the XSS attack and how Grails takes care of it summed up the chapter.
The Grails operator overloading made an entrance to the 4th chapter. Java pros who are looking for leveraging Grails in their projects will certainly appreciate it. While the other books covered a lot about this topic, this one laid out just enough to add some new features to the web application. What I was pleasantly surprised by were the two methods - redirect() and render() which I had known existed in the Grails controllers, but had never understood they're added dynamically exactly as the methods of Grails domain classes. I didn't know that defining Groovy variables with the def keyword creates GroovyObject instances either. I had thought it's merely an Object instance. The other interesting points were about scripts in packages and asserts in Groovy turned on by default and out of the sudden (as it was not enough about Groovy) the author presented Groovy in more details. The so-called "whirwind tour of the Groovy language" was very informatory yet it made a gentle entry into the world of Groovy programming. The basics were laid out in a comprehensible manner.
The 5th chapter made a good point about grails.project.plugins.dir in BuildConfig.groovy so it's not an issue anymore to upgrade Grails while developing your applications with plugins. It was then when the first plugin in this book - JSecurity - was presented and why the dynamic finders are called dynamic. It's not that they're added dynamically, but...well, I'm sure you don't want me to spoil it. Read about it in the book. It's clear that the book was written by a Groovy/Grails practitioner at the very least (if not a Groovy/Grails guru). While presenting JSecurity there're the tip and trick block about accessControl in filters. I was about to have complained it's not fully explained when the block appeared. Exactly when needed. When it was clear that the controllers were doing too much work, the author showed Grails services. Keeping the pace was not an issue at all. Again, exactly in time when the different parts of Grails were presented. The book answered some of the questions which every web application developer has to work out and so did for the "n+1 queries" issue.
The 6th chapter made valid points about testing approaches and why they're necessary. I'd call it a testing refresher. Testing is quite often considered as an added benefit and only a few can take hassle to write them, but Grails simplifies it to an extreme minimum. The book presented it well and I'm sure that after having read the chapter nobody will ever be able to ignore it.
What I didn't like in the chapter 7. was the decision about storing the files in the database without much explanation why. I could find one myself, but I wish I had read about the author's take on it.
The chapter 9. turned its attention to the issue of developing controllers with too much business logic instead of just controlling the flow and using Grails services for it. Again, it's easy to repeat what's generally considered as a best practice, but it was this book that explained it to me clearly so it eventually became obvious. The part of the chapter about loosely- vs strongly-typed parameters was very informatory too. I'm not sure I could read about it in the other books.
The chapter 10. mentioned a bit about folksonomy which I had never heard before. Explaining the collect() method and the Elvis operator briefly was just enough to implement the necessary features in the web app. The author paid much attention to learning by mistakes and test-driven development. GORM inheritance was explained briefly with unimportant stuff left out. Grails 1.1 new feature - the template namespaces - was very precious addition.
The chapter 11. presented Prototype and RichUI plugins whereas the chapter 12. came with the Searchable plugin. As the author said it was "one more, but this time we can use this as an opportunity to become more familiar with Groovy builders, rather than instantly another plugin". Quite a pragmatic approach, isn't it? It was again explained what the differences between Grails controllers and services are. Enough to keep that in mind for the rest of my life. Good design was a foundation for the book and the author never forgot to point out its benefits. New REST service mapping in Grails 1.1 was explained too. As the wrap-up for the chapter the author showed how to create a simple command for GAnt, which was just on a single page without even mentioning GAnt by its name.
In the chapter 13. the author took "a closer look at how other plug-ins work so we could borrow some ideas from them". Taking it all in small steps helped a lot. There was a plan laid out, small discussion and implementation afterwards. It seems a lot of work, but the book made it very slick. It was however a very tough chapter which I barely understood. These advanced topics about developing your own Grails plugin were beyond my mental capabilities.
The last chapter was about setting up an environment with MySQL and Tomcat. I was glad to have read the Next Steps chapter about GORM-JPA, integration with other presentation frameworks and data migration. I wish the chapter about presentation frameworks with GWT and Wicket mentioned had been longer. Perhaps a good idea for the next book about Grails?
As the summary goes: "Each chapter builds on a sample application so that everything you learn about Grails is in the context of real examples". I could only add that the sample app turned out to be a fully-fledged webapp. There're some typos in the book too, but they're harmless and one should not even take it into account while making a decision to read it or not. You should definitely read it and I wish you find the book as much informative as I did.
