我需要调用静态资源插件(http://www.grails.org/Static+Resources+Plugin)来自我的域类。
这在控制器中完美运行:
def tstLink = resourceLinkTo(dir:"docs/${identifier}",file:originalFileName)
但在域类中我得到
Exception Message: No signature of method: static org.maflt.ibidem.Item.resourceLinkTo() is applicable for argument types: (java.util.LinkedHashMap) values: [[dir:docs/19e9ea9d-5fae-4a35-80a2-daedfbc7c2c2, file:2009-11-12_1552.png]]
我认为这是一个普遍问题。
那么如何将 taglib 作为域类中的函数来调用呢?
不久前,我在开发一个应用程序时遇到了这个问题。我最终做的是在服务方法中调用标签:
class MyService {
def grailsApplication //autowired by spring
def methodThatUsesATag(identifier, originalFileName) {
//This is the default grails tag library
def g = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib')
g.resourceLinkTo(dir:"docs/${identifier}",file:originalFileName)
}
}
然后在我的域类中,我也可以通过 spring 自动装配来访问该服务:
class MyDomain {
String originalFileName
def myService //autowired
static transients = ['myService'] //Necessary so that GORM doesn't try to persist the service instance.
//You can create a method at this point that uses your
//service to return what you need from the domain instance.
def myMethod() {
myService.methodThatUsesATag(id, originalFileName)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)