Suppose I have the following configuration in a conf/InjectionConfig.groovy file:
x { a = { attrs, body -> out << "hello" } b = { attrs, body -> out << "goodbye" } }
and that I have a simple taglib such as
class XTagLib { static namespace = "x" }
What I want to do is that when I type <x:a /> for any of my views, it prints hello . I already tried to insert these taglib metaclasses as a property and method, but none of them work. As an example, here is basically what I'm doing right now in the service:
public void afterPropertiesSet() throws Exception { GroovyClassLoader classLoader = new GroovyClassLoader(getClass().classLoader) def slurper = new ConfigSlurper(GrailsUtil.environment) ConfigObject xConfig try { xConfig = slurper.parse(classLoader.loadClass('InjectionConfig')) } catch (e) { e.printStackTrace() } xConfig.x.each({ if ( !XTagLib.metaClass.hasMetaProperty(it.key) ) { XTagLib.metaClass.registerBeanProperty(it.key, { args -> def attrs = args[0], body = args[1] it.value.call(attrs, body) } } }) }
Am I just doing it wrong or is it possible now?
source share