Is there a way to call a taglib closure from inside the grails console? I want to be able to get at the message tag within the grails console and I can not figure this out...
+2
A:
You can get the configured taglib, but most expect to be running in the context of a web request. To get around that you can bind a mock request:
import grails.util.GrailsWebUtil
GrailsWebUtil.bindMockWebRequest ctx
def g = ctx.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib')
String message = g.message(code: 'default.button.delete.confirm.message')
You can also get messages for other languages by setting the locale of the request, e.g.
import grails.util.GrailsWebUtil
def webRequest = GrailsWebUtil.bindMockWebRequest(ctx)
webRequest.currentRequest.addPreferredLocale(Locale.GERMANY)
def g = ctx.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib')
String message = g.message(code: 'default.button.delete.confirm.message')
Burt Beckwith
2010-05-06 16:58:17