0

I'm developing an Apache Sling WCMS and using java tag libs to rendering some data.

I'm using IntelliJ IDEA 10.0

I defined a jsp tag lib with following descriptor and handler class:


TLD file contains:

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
  <tlib-version>1.0</tlib-version>
  <short-name>taglibdescriptor</short-name>
  <uri>http://bob/taglibs</uri>
  <tag>
      <name>testTag</name>
      <body-content>tagdependent</body-content>
      <tag-class>org.bob.taglibs.test.TestTagHandler</tag-class>
  </tag>
</taglib>

Tag handler class:

package org.bob.taglibs.test;

import javax.servlet.jsp.tagext.TagSupport;

public class TestTagHandler extends TagSupport{

    @Override
    public int doStartTag(){
        try {
            pageContext.getOut().print("<h1>Helloooooooo</h1>");
        } catch(Exception e) {
            return SKIP_BODY;
        }
        return EVAL_BODY_INCLUDE;
    }
}

I packaged the tag lib as BobTagLib.jar and deployed it as a bundle using Sling Web Console.


I used this tag lib in a jsp page deployed in my Sling repository:

index.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="bob" uri="http://bob/taglibs" %>

<html>
  <head><title>Simple jsp page</title></head>
  <body>
     <bob:testTag/>
  </body>
</html>

(Edited) MANIFEST.MF

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: Bob Tech
Built-By: babak
Bundle-Version: 1.0.0
Bundle-Name: Bob Tag Library
Build-Jdk: jdk1.6.0_18
Bundle-Vendor: The Bob Technology Foundation
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.bob.taglibs
Bundle-Category: sling

Calling the page cause the following exception:

org.apache.sling.scripting.jsp.jasper.JasperException: /apps/TagTest/index.jsp(7,5) Unable to load tag handler class "org.bob.taglibs.test.TestTagHandler" for tag "bob:testTag"
...

Can any one get me a solution?

In advance, any help is apreciated.

Babak Behzadi
  • 1,236
  • 2
  • 16
  • 33
  • Look for extension points to add resources from other bundles to the jasper class loader. The issue is that your JasperClassLoader using its bundle class loader is not finding the tag class on its classpath. Also look at eclipse-register-buddy to maybe get it on the class path but that seems to be the issue. – Duncan Krebs Nov 14 '12 at 23:43
  • Do you mean I need pom.xml configuration in META-INF of the tag lib? – Babak Behzadi Nov 15 '12 at 05:55

1 Answers1

2

It looks like your taglib is found but the org.bob.taglibs package is not exported by your bundle, so not visible to JSP scripts and from other bundles.

Adding an

Export-Package: org.bob.taglibs.*;version=1.0 

header to your MANIFEST.MF should fix that.

If that doesn't solve your problem you might want to compare your taglib with the Sling JSP taglib which is known to work.

Bertrand Delacretaz
  • 6,100
  • 19
  • 24
  • Thanks for your answer but it didn't solve my problem. Should I define another configuration like pom.xml in my lib package? – Babak Behzadi Nov 15 '12 at 08:46
  • There's various ways of building your bundle, and yes Maven is my favorite one, you can take the Sling JSP taglib mentioned above as an example. – Bertrand Delacretaz Nov 15 '12 at 12:35