【发布时间】:2013-01-30 15:27:04
【问题描述】:
我正在尝试自定义出色的 FilterPane grails 插件的 HTML 标记,但是遇到了一些困难。 FilterPane 提供了一堆标签来呈现搜索/过滤表单,我想在我的应用程序中覆盖这些标签。
我原以为我可以简单地复制我想从
覆盖的_tagName.gsps
plugins/filterpane-2.0.1.1/grails-app/views/filterpane
进入
grails-app/views/filterpane
并修改它们,但是如果使用指定的插件名称属性调用渲染方法,Grails 似乎从不检查应用程序是否覆盖插件的视图。
org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateRenderer.findAndCacheTemplate 在私有方法中包含以下代码:
...
GroovyPageScriptSource scriptSource;
if (pluginName == null) {
scriptSource = groovyPageLocator.findTemplateInBinding(templatePath, pageScope);
} else {
scriptSource = groovyPageLocator.findTemplateInBinding(pluginName, templatePath, pageScope);
}
...
所以当指定一个非空的pluginName 时,我们只是抓取插件的视图,从不检查应用程序是否覆盖它。
我认为解决此问题的一种简单方法是仅覆盖 GrailsConventionGroovyPageLocator.findTemplateInBinding 或 GrailsConventionGroovyPageLocator 中的其他类似方法,但似乎也无法在 Grails 应用程序中执行此操作!
我创建了一个覆盖GrailsConventionGroovyPageLocator 的简单类,将findTemplateInBinding 方法替换为在检查插件视图之前检查应用程序视图目录的方法。然后我修改了resources.groovy,添加了一个doWithSpring闭包来替换默认groovyPageLocator的beanClass属性:
def doWithSpring = {
def pageLocator = delegate.getBeanDefinition("groovyPageLocator")
pageLocator.beanClass = MyConventionGroovyPageLocator
}
但是,当我的应用程序启动时,它似乎没有被调用。
我真的很茫然。我原以为这很简单,但它变成了一些蠕虫。有没有人有什么建议?我要做的就是覆盖插件提供的视图...
【问题讨论】:
标签: grails plugins view gsp taglib