Search code examples
javajspjboss7.xcustom-tags

jsp Custom Tag: doAfterBody method is not invoked


The below code is not working in JBoss 7. I have also tested it in Tomcat 7.

The root cause is constructor and doAfterBody method is not invoked for <xml> tag. Even though it is getting invoked for parent tag <xslt>.

When child tag <xml> is moved outside <xslt> then it works. That means child tag is not recognised.

.tld file:

<?xml version="1.0" encoding="UTF-8"?>

<taglib>
  <tlib-version>1.0</tlib-version>
  <jsp-version>1.2</jsp-version>
  <short-name>xx</short-name>
  <uri></uri>

  <tag>
    <name>xml</name>
    <tag-class>com.mycompany.XsltXmlTag</tag-class>
    <body-content>tagdependent</body-content>
  </tag>

  <tag>
    <name>xslt</name>
    <tag-class>com.mycompany.XsltTag</tag-class>
    <body-content>tagdependent</body-content>
  </tag>

</taglib>

tag class for <xml> tag:

public class XsltXmlTag extends BodyTagSupport {

    public XsltXmlTag() {
        log("constructor not invoked.");
    }

    public int doAfterBody() throws JspException {
        log("this method is not invoked.");
        ...
    }

    ...
}

jsp:

<%@ taglib uri="xmlx.tld" prefix="x"%>

...

<x:xslt media="html">
    <x:xml>
        <?xml version="1.0" ?>
        ...
    </x:xml>

    ...
</x:xslt>

it is working in Tomcat 7, after setting <body-content> to jsp instead of tagdependent. But, in JBoss 7, tld validation is failing for <body-content>jsp</body-content>

In JBoss 7, it works with <body-content>scriptless</body-content>. But, I have scripts such as <%= contextPath%> and <jsp:expression> inside <xml> tag.

how to fix it?


Solution

  • child tag <xml> is processed after setting <body-content> to scriptless. And, have replaced scripts inside <xml> tag with custom tags.