I\'m trying to use g.render in a grails service, but it appears that g is not provided to services by default. Is there a way to get the templating engine to render a view
Here's a solution that's similar to Stefan's, but a bit simpler
import org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
class MyService implements ApplicationContextAware {
private ApplicationTagLib g
void setApplicationContext(ApplicationContext applicationContext) {
g = applicationContext.getBean(ApplicationTagLib)
// now you have a reference to g that you can call render() on
}
}