Grails 2.0 action arguments data binding

20 / Feb / 2012 by Uday Pratap Singh 0 comments

One feature that I really like in Grails 2.0 is action arguments databinding. While reading more about it I also found a nice grails.web.RequestParameter annotation. When you know something you always find its use case. In my recent project I need to take radius and height as params for creating a cylinder so my action looks like

def save(float radius, float cylinder){
....
}

but now I have changed my action as

def save(@RequestParameter('r')float radius, @RequestParameter('h')float height){
....
}

Now radius will initialize with params.r and height will initialize with params.h. It made my urls short and my code more readable.
I believe that the real benefit of this annotation would be in a scenario where an external API returns some result whose fields are not that intuitive.
However I have a wish here, that if we could use this annotation on command object fields as well then it will be more useful.


Hope it helps
Uday Pratap Singh
uday@intelligrape.com

FOUND THIS USEFUL? SHARE IT

Leave a comment -