Overriding plugins in Grails 2.2

I am trying to customize the HTML markup of the excellent FilterPane grails plugin, however I have some difficulties. FilterPane provides a bunch of tags to render the search / filter form, and I would like to override them in my application.

I thought I could just copy _tagName.gsp , which I would like to override from

plugins/filterpane-2.0.1.1/grails-app/views/filterpane

in

grails-app/views/filterpane

and modify them, however, it seems that Grails never checks if the application overrides the plugin's views if the render method is called with the specified property of the plugin name.

org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateRenderer.findAndCacheTemplate contains private code in a private method:

 ... GroovyPageScriptSource scriptSource; if (pluginName == null) { scriptSource = groovyPageLocator.findTemplateInBinding(templatePath, pageScope); } else { scriptSource = groovyPageLocator.findTemplateInBinding(pluginName, templatePath, pageScope); } ... 

therefore, when a non-zero pluginName , we just grab the plugin's view and never check if this application overrides.

I thought an easy way around this problem would be to simply override GrailsConventionGroovyPageLocator.findTemplateInBinding or some other similar method in GrailsConventionGroovyPageLocator , however, it seems impossible to do this from a Grails application or

I created a simple class that overrides GrailsConventionGroovyPageLocator , replacing the findTemplateInBinding method findTemplateInBinding the one that checks the application view directory before checking it. Then I changed resources.groovy by adding a doWithSpring closure to replace the default groovyPageLocator :

 def doWithSpring = { def pageLocator = delegate.getBeanDefinition("groovyPageLocator") pageLocator.beanClass = MyConventionGroovyPageLocator } 

However, this does not seem to trigger when my application starts.

I am really at a loss. I expected it to be simple, but it turned into a piece of worms. Anyone have any suggestions? All I want to do is to override the views provided by the plugin ...

+4
source share
3 answers

You can change the source of the plugin instead of changing the location of the template.

Location: user_home\.grails\version\projects\project\plugins\plugin-name

0
source

I'm not an expert on grails, but in order to redefine plugins, you have to recreate them in your main project views folder. For example, I modified /auth/login.gsp from the Spring Security Plugin by simply creating the same thing in my /project/views/auth/login.gsp . If you make changes to the plugin files, you may lose them if you remove the plugin.

0
source

To change the view in the plugin template, run the command

grails install-templates

a source

This will copy the plugin templates into your project, which you can then customize. What this does, for example, a plugin for forests, is to copy the files to src / templates / scaffolding (note, not grails-app / templates / scaffolding). So in your case, I would try to copy the files to src / views / filterpane

0
source

All Articles