I am trying to run GSP views in simple Spring MVC application (without Spring Boot). I am trying to duplicate the example located here: https://github.com/grails/grails-boot/tree/master/sample-apps/gsp but I am trying to run it in plain Spring MVC environment.
I have successfully reached the phase when GSP pages are rendered, some g: tags are even working (for example g:if and g:each) but there is a problem when I try to add a tag library. I have set up a simple tag library as follows:
@TagLib
@Component
class ExampleTaglib {
static namespace = "xx"
Closure testtag = { attrs, body -> // simple "def" leads to tag not being found
out << "Test"
}
}
When I try to use that tag I have an error: No such property: out.
I have spent some time debugging that problem and it shows up that the AST Transformation that adds methods from org.codehaus.groovy.grails.plugins.web.api.TagLibraryApi
seems not to be applied (I have compiled the taglib using groovyc and all required libraries - there is no getOut()
method in resulting .class file).
On the other hand I see that compiled taglibs in Grails project have this tranformation applied (I can see the getOut()
method while viewing compiled .class file).
Is there any reason that there is no getOut()
method in the compiled class file? Is the Grails taglib compilation process different from compiling the taglib manually?
If anyone is interested after long sessions of debugging i found solution for this problem... It seems that the taglib class name has to end with 'TagLib' (case sensitive) my class was named 'ExampleTaglib' (lower case 'L') and therefore the AST transformation was not applied (not matching the grails convention). The class name check check is done in second
if
of theAbstractGrailsArtefactTransformer#isValidArtefactTypeByConvention
method.