For example, i can put
<g:createLink controller="user" action="show" />
inside a .gsp file and it will work nicely.
But also I'd like to use the same closure createLink
inside a .groovy file which is not part of the grails views
For example, i can put
<g:createLink controller="user" action="show" />
inside a .gsp file and it will work nicely.
But also I'd like to use the same closure createLink
inside a .groovy file which is not part of the grails views
For unmanaged classes you can reference the
g
taglib with:The native way to do this as of Grails 2.0 outside of controllers (so for services, async jobs, etc) is to use the LinkGenerator class. Works everywhere and mentioned in the official docs. See example here
http://mrhaki.blogspot.ca/2012/01/grails-goodness-generate-links-outside.html
You can use taglib methods from Grails controllers, for example:
For builtin taglibs (or those in the g namespace) you can omit the namespace prefix in the method call.
Inject the grailsApplication into your service/filter.
And get the Spring bean.