I was having a use-case where I need to use grails taglib, In this taglib I have a tag from which I need to return a map but I struggling with that as grails taglib by default return’s StreamCharBuffer e.g
class ObjectReturningTagLib { static namespace = "custom" def mytag = { attrs -> def data=[:] // Some processing on data //returns an object //can be a boolean return data } }
In this case the returned data is of type StreamCharBuffer
If I want returned data is of type Map then we need to introduced
static returnObjectForTags = ['mytag']
returnObjectFromTags specifies which tag changed from default behavior and returns an object instead.
So the version of tag which returns an object is:
class ObjectReturningTagLib { static namespace = "custom" static returnObjectForTags = ['mytag'] def mytag = { attrs -> def data=[:] // Some processing on data //returns an object //can be a boolean return data } }
Note: In case we want to return object than we have to use return keyword and not out
Recent Comments