tags:

views:

545

answers:

1

I'm using grails and want to use an in-house custom JSP taglib in the project. Does anyone know how to do this? I've seen references to getting other jsp taglibs working but not if you've written them yourself. I have a jar file called 'common-view.jar' in the lib folder and have tried this code to reference it:

<%@ 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 greatly appreciated.

Matt

A: 

modify the "web-app/WEB-INF/tld/grails.tld" file 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>

put common-view.jar in the lib directory. and it should be ready to go!

NOTE: about the namespace - in GSP, i think the global g: namespace can be used to refer to your tag above.

For more info, check out this page - its a bit hard to distill it, but if you've done jsp/servlets, it should be pretty understandable. http://grails.org/Dynamic+Tag+Libraries

Edit: i was able to extract more info from this bug report than the above doco page : http://jira.codehaus.org/browse/GRAILS-4571 . Essentially, you would add the tag declaration to either grails.tld or your own (if you use grails.tld, you wont need to declare a taglib on the page you are using that tag (i.e., <%@ taglib prefix="jct" uri="/WEB-INF/tld/jsp-custom-tags.tld"%>). Make sure your jar containing the taglib is in the classspath. Putting it in /lib/ will work nicely.

Chii
Thanks for the answer but I just get: 2009-09-28 13:49:19,636 ERROR [errors.GrailsExceptionResolver] Error processing GroovyPageView: Tag [cascaidBody] does not exist. No tag library found for namespace: gWhen I try and use this.
Matt
you should post your grails.tld file for diagnosis
Chii