Grails - use custom JSP taglib

I am using grails and want to use my own JSP taglib project in the project. Does anyone know how to do this? I've seen links to other jsp taglibs at work, but not that you wrote them yourself. I have a jar file named "common-view.jar" in lib folder and tried using this code to link:

<%@ taglib uri="${createLinkTo(dir:'lib',file:'common-view.jar')}" prefix="cas_common" %>

      

And then in the code I use:

<cas_common:body>${career.jobSections.sectionWorkActivities}</cas_common:body>

      

I get:

org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Could not parse script

      

Any help is greatly appreciated.

Matt

+2


source to share


1 answer


modify the file "web-app / WEB-INF / tld / grails.tld" and add the necessary entries that point to your class:

<tag>
    <name>includeJs</name>
        <tag-class>com.mycompany.taglib.IncludeJsTag</tag-class>
        <body-content>JSP</body-content>
        <variable>
            <name-given>it</name-given>
            <variable-class>java.lang.Object</variable-class>
            <declare>true</declare>
            <scope>AT_BEGIN</scope>
        </variable>
        <dynamic-attributes>true</dynamic-attributes>
</tag>

      

place common-view.jar

in lib directory. and it should be ready to go!



NOTE. As far as namespace is concerned - in GSP, I think the global namespace g: can be used to refer to your tag above.

For more information, check out this page - it's a little difficult to redo, but if you've done jsp / servlets it should be pretty clear. http://grails.org/Dynamic+Tag+Libraries

Edit: I was able to extract more information from this bug report than the previous doco page: http://jira.codehaus.org/browse/GRAILS-4571 . Basically, you would add a tag declaration to either grails.tld or your own (if you are using grails.tld you do not need to declare taglib in the page you are using with that tag (i.e. <%@ taglib prefix="jct" uri="/WEB-INF/tld/jsp-custom-tags.tld"%>

). Jar containing taglib is in the classpath, inserting it into / lib / will work nicely.

+1


source







All Articles