{"id":23,"date":"2008-09-16T10:47:29","date_gmt":"2008-09-16T05:17:29","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=23"},"modified":"2015-07-10T17:54:02","modified_gmt":"2015-07-10T12:24:02","slug":"how-to-invoke-a-gsp-tag-as-a-method-in-grails-gsp","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-invoke-a-gsp-tag-as-a-method-in-grails-gsp\/","title":{"rendered":"How to invoke a GSP tag as a method in Grails GSP"},"content":{"rendered":"<p><a title=\"Grails Outsourcing\" href=\"http:\/\/www.tothenew.com\/grails-application-development\">Grails has a lot of gems<\/a>. One of my favorites (besides GORM) is GSP tags &#8212; Grails makes it so easy to create new tags, now there is no reason to write java\/groovy code inside GSPs.<\/p>\n<p>One of the features about GSP tags that I discovered and used today is that it is possible to invoke a GSP tag as a method call and assign the output of the tag to a variable.<\/p>\n<p>Lets jump to the example:<\/p>\n<p><span style=\"color: #003366;\">&lt;g:def var=&#8221;currentDomain&#8221; value=&#8221;${siteConfig.property(name:&#8217;regDomain&#8217;)}&#8221; \/&gt;<\/span><\/p>\n<p>In the above example:<\/p>\n<p><span style=\"color: #003366;\">siteConfig<\/span> : is the namespace of my taglib.<\/p>\n<p><span style=\"color: #003366;\">property<\/span> : is the name of the tag<\/p>\n<p><span style=\"color: #003366;\">name<\/span> : is the name of the attribute that I am passing to my tab<\/p>\n<p><span style=\"color: #003366;\">regDomain<\/span> : is the value of the &#8216;name&#8217; attribute.<\/p>\n<p>The output from the tag is stored in <span style=\"color: #003366;\">currentDomain<\/span> variable.<\/p>\n<p>Not sure if something similar is possible with plain JSP tags.<\/p>\n<p>-Deepak<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Grails has a lot of gems. One of my favorites (besides GORM) is GSP tags &#8212; Grails makes it so easy to create new tags, now there is no reason to write java\/groovy code inside GSPs. One of the features about GSP tags that I discovered and used today is that it is possible to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[7],"tags":[4840,9,32],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}