tags:

views:

101

answers:

1

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