Is possible to overwrite the behaviour of the methods **CreateLink** and **CreateLinkTo**?
Is possible to overwrite the behaviour of the methods CreateLink and CreateLink开发者_运维问答To?
You could use meta programming to replace the closure on ApplicationTaglib.
ApplicationTagLib.metaClass.getCreateLink = {->
return {attrs->
// your code here
}
}
I've never tried it but it might work :)
All you need to do is create a taglib of your own and define the tags yourself ie
class MyTabLib {
def createLink = {attrs, body ->
.... etc ....
}
def createLinkTo = {attrs, body ->
.... etc ....
}
}
Grails will use your taglib first.
Hope this Helps!
This is a little late, but the solutions above didn't work for me. I was able to successfully do this, though:
public class MyTagLib extends ApplicationTagLib {
def oldResource
public MyTagLib() {
// save the old 'resource' value
oldResource = resource;
resource = staticResource;
}
def staticResource = { attrs ->
// dork with whatever you want here ...
// ...
out << oldResource(attrs);
}
}
you're basically extending the original tag lib. Since the 'resource' tag is a property of the object (and not a method) I don't think you can actually override it. Instead, just save the original value and call it after you've make your changes to the tag request.
精彩评论