Wednesday, July 22, 2009

Spring Roo vs Grails generated controllers



As I already tweeted earlier today I was trying out Spring Roo 1.0.0.RC1 as it was released today.

After playing a couple of hours with Roo I must say really like Roo using AspectJ inter-type declarations (ITDs). For example Roo will automaitcally generate id and version fields and getters and setters for your persistent fields in your domain class. Roo generates these at development time in separate AspectJ .aj files. As a developer you won't touch them as Roo will manage and update them automatically as you add fields etc. to domain classes. The great thing is the generated code will not interfere with your custom code and you don't have to be scared you custom or overwritten methods are overwritten by Roo again. During compilation all .aj files belonging to the Java class are compiled into just 1 .class file.

What I really liked is that when you are developing in SpringSource Tool Suite (based on Eclipse) code completion works also for methods contained in the AspectJ .aj files. So also debugging your code is a real breech as you can step through the methods generated by Roo easily.

Roo also contains scaffolding. However as a long term Grails user I got scared when I saw the controller code generated by Roo. See the example below:

Roo generated controller code:


@org.springframework.web.bind.annotation.RequestMapping(value = "/nation", method = org.springframework.web.bind.annotation.RequestMethod.GET)
public java.lang.String NationController.list(org.springframework.ui.ModelMap modelMap) {
modelMap.addAttribute("nations", com.footdex.domain.Nation.findAllNations());
return "nation/list";
}


Grails generated controller code:

def list = {
params.max = Math.min(params.max ? params.max.toInteger() : 10, 100)
[nationList: Nation.list(params), nationTotal: Nation.count()]
}


OK, the Roo generated code could look better if we remove all the package information before the classes:

@RequestMapping(value = "/nation", method = RequestMethod.GET)
public String list(ModelMap modelMap) {
modelMap.addAttribute("nations", Nation.findAllNations());
return "nation/list";
}


But then we should also just create the same functionality in the Grails controller (without paging):

def list = {
[nationList: Nation.list()]
}


So which one do you prefer?

I really think Spring Roo will have a great future. The use of ITDs for generated code and it's support in SpringSource Tool Suite will really aid adoption. Also in case Grails is not allowed within your company, Roo could really help you to get more productive.

As I expressed already in my example I really like Grails/Groovy effectiveness and readiness of code. Also the deep level of code by convention empowered by Grails is unbeatable.

With Grails and Roo, SpringSource has 2 remarkable frameworks in it's portfolio. Let them be as innovative as always and we as developers are the winners!

Thursday, July 9, 2009

2nd NLGUG Meetup



Yesterday was the 2nd NLGUG (Dutch Groovy and Grails User Group) meetup in Baarn (close to Amsterdam).
As I live in the south of The Netherlands (close to Maastricht) attenting the meetup meant a 2-hour drive home. So at 00.10 I arrived home, tired, but it was worth it!

The meetup was organized by Erik Pragt and was hold at the VX Company headquarters. We really need to meetup up at Valid's new V-Tower at Eindhoven Flight Forum one day! Perhaps somewhere in October or November when we are settled in.

I must admit that I was not really attracted by the subject: iWebKit
But Sebastien Blanc's workshop turned out to be really fun and impressive!
After a short presentation we did a workshop by building our own Twitter client for the iPhone. And guess what it even worked and looked nice on my Android phone. Now iWebKit only need to support native Android look and feel (feature request?).

We used the Grails iWebKit Plugin (developed by Sebastien himself) and the Twitter Plugin and it's so impressive and cool to see that with a couple lines of code you can build a Twitter client for your mobile. Sebastien promised to put the workshop online so the rest of the world can try it to.

I guess there were around 15 attendees and it's really great to see how enthousiastic they are. Grails also lives in The Netherlands! Hope next time there will be even more people. Check out some photo's of the meetup.

Tuesday, July 7, 2009

Grails Google Analytics Plugin



As Marc Palmer already mentioned it's important for the community to download and test Grails 1.2-M1.

I've already started with 1.2-SNAPSHOT builds for my home project but also decided to write a simple Google Analytics plugin and test the plugin development parts of Grails 1.2-M1. Again, it is a very simple plugin but found no blocking issues so far.

About the plugin: It includes a simple tag to embed the Google Analytics tracking code in your views/layouts. Just add <ga:trackPageview /> just before your closing </body> tag and add your Web Property ID to Config.groovy:

// grails google analytics plugin configuration
google.analytics.webPropertyID = "UA-xxxxxx-x"


By default only running your Grails application in production mode the Google Analytics tracking code will be outputted. This makes sense as you don't want to mix development or testing page hits with the ones from production. However if you need you can explicitly enable/disable Google Analytics or use different Web Property ID's per environment. See http://www.grails.org/plugin/google-analytics for details.