{"id":5106,"date":"2012-02-20T22:07:13","date_gmt":"2012-02-20T16:37:13","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=5106"},"modified":"2016-12-19T15:06:19","modified_gmt":"2016-12-19T09:36:19","slug":"grails-2-0-action-arguments-data-binding","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-2-0-action-arguments-data-binding\/","title":{"rendered":"Grails 2.0 action arguments data binding"},"content":{"rendered":"<p>One feature that I really like in Grails 2.0 is action arguments <a href=\"http:\/\/grails.org\/doc\/latest\/guide\/theWebLayer.html#dataBinding\">databinding<\/a>. 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<br \/>\n[java]<br \/>\ndef save(float radius, float cylinder){<br \/>\n&#8230;.<br \/>\n}<br \/>\n[\/java]<br \/>\nbut now I have changed my action as<br \/>\n [java]<br \/>\ndef save(@RequestParameter(&#8216;r&#8217;)float radius, @RequestParameter(&#8216;h&#8217;)float height){<br \/>\n&#8230;.<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Now radius will initialize with params.r and height will initialize with params.h. It made my urls short and my code more readable.<br \/>\nI 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.<br \/>\nHowever I have a wish here, that if we could use this annotation on command object fields as well then it will be more useful.<br \/>\n<br \/>\nHope it helps<br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/author\/uday\/\">Uday Pratap Singh<\/a><br \/>\n<a href=\"mailto:uday@intelligrape.com\">uday@intelligrape.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[7],"tags":[766,768,664,765,767],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5106"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=5106"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/5106\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=5106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=5106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=5106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}