I'm trying to apply @GrailsCompileStatic to taglib and geting the following error:
Error:(19, 16) Groovyc: [Static type checking] - Cannot find matching method com.tempvs.image.MyTagLib#render(java.util.LinkedHashMap ). Please check if the declared type is right and if the method exists.
Code example:
@GrailsCompileStatic
class MyTagLib {
...
String myTag = { Map attrs ->
...
out << render(template: '/templates/myTemplate', model: [...])
}
}
What am I doing wrong and how can I solve the problem?
You are using some dynamic features, because taglibs in general do use them. Even just calling "render" is in a sense dynamic.
If you really want to, you can work around this by injecting a PageRenderer and using that to render your page, and then outputting the resulting HTML. I'm not sure it would be worth it, but I certainly don't know your performance requirements!
Example:
This works, but you will have some work ahead of you if your taglib is doing anything remotely complex, because EVERY call to render, or any other tag is going to have to be replaced by a statically compiled call. It's possible, but possibly not hugely beneficial.