Reputation: 5651
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
Upvotes: 2
Views: 2744
Reputation: 14738
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.
Upvotes: 1