How to invoke a GSP tag as a method in Grails GSP

16 / Sep / 2008 by Deepak 0 comments

Grails has a lot of gems. One of my favorites (besides GORM) is GSP tags — 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 invoke a GSP tag as a method call and assign the output of the tag to a variable.

Lets jump to the example:

<g:def var=”currentDomain” value=”${siteConfig.property(name:’regDomain’)}” />

In the above example:

siteConfig : is the namespace of my taglib.

property : is the name of the tag

name : is the name of the attribute that I am passing to my tab

regDomain : is the value of the ‘name’ attribute.

The output from the tag is stored in currentDomain variable.

Not sure if something similar is possible with plain JSP tags.

-Deepak

FOUND THIS USEFUL? SHARE IT

Tag -

Grails Groovy gsp

Leave a Reply

Your email address will not be published. Required fields are marked *