开发者

grails access controller from taglib

Is it possible to access the current controller instance from within a TagLib? For example:

class FooTagLib {
    static namespace = 'foo'

    def msg = { attrs, body ->         开发者_如何学JAVA 
      // Can I get a reference to the current controller here?
    }
}

I want to do this because I store some data in a property of the controller and want to access it within the TagLib. I realise this may sound strange, but just humour me....


Inside your msg tagLib:

grailsApplication.getArtefactByLogicalPropertyName('Controller', pageScope.controllerName)

Like Views, you have access to the current controller and action through controllerName and actionName


Try something like this...

def ctl = grailsApplication.getArtefactByLogicalPropertyName('Controller', 'whateverController') 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜