I'm trying to use grails internal taglib from a service but I receive this error:
No signature of method: MyService.message() is applicable for argument types: (java.util.LinkedHashMap) values: [[code:default.app.name]]
This is the code I'm using:
class MyService {
def myMethod() {
def appName = message(code: 'default.app.name')
}
}
Grails 3
The solution is to inject the
grailsApplication
object and use its context to get the taglib bean:Grails 2
With older grails version the class package is slightly different:
If you try to use this package with newer grails version (3+), you'll receive an error:
Custom taglib
With any version, if you need to use your custom taglib from a service just use a code like this: