Does Tomcat support the JSP body content for a BodyTag?  In my doAfterBody
method (inherited from BodyTagSupport), I return EVAL_BODY_TAG.  I have some
debug statements in my code, so I can see that the doAfterBody method is
called multiple times, but I'm not seeing the html that should be generated
by my JSP code within the tag's body.  Can somebody help me?

************************************************
Here's my Java code...

package ws.carman.taglib;

import javax.servlet.jsp.tagext.BodyTagSupport;
import java.util.Iterator;
import java.util.Collection;
import javax.servlet.ServletRequest;

public class IterateTag extends BodyTagSupport
{
  private String m_CollectionName;
  private String m_ElementName;
  private Iterator m_Iterator;

  public final void setCollectionName( final String newCollectionName )
  {
    m_CollectionName = newCollectionName;
  }

  public final void setElementName( final String newElementName )
  {
    m_ElementName = newElementName;
  }

  public final int doStartTag()
  {
    final ServletRequest request = pageContext.getRequest();
    final Collection coll = ( Collection )request.getAttribute(
m_CollectionName );
    m_Iterator = coll.iterator();
    return doNext();
  }

  public final int doAfterBody()
  {
    System.out.println( "Inside doAfterBody!" );
    return doNext();
  }

  private final int doNext()
  {
    if( m_Iterator.hasNext() )
    {
      pageContext.getRequest().setAttribute( m_ElementName,
m_Iterator.next() );
      System.out.println( "Current element is " +
pageContext.getRequest().getAttribute( m_ElementName ) );
      return EVAL_BODY_TAG;
    }
    else
    {
      return SKIP_BODY;
    }
  }

  public void release()
  {
    m_ElementName = null;
    m_CollectionName = null;
    m_Iterator = null;
  }
}

*********************************************************
Here's the tag library descriptor file...

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
 PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
 "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<!-- a tag library descriptor -->

<taglib>
  <tlibversion>1.0</tlibversion>
  <jspversion>1.1</jspversion>
  <shortname>carman</shortname>
  <uri></uri>
  <info></info>
  <bodycontent>JSP</bodycontent>
  <tag>
    <name>iterate</name>
    <tagclass>ws.carman.taglib.IterateTag</tagclass>
    <info>Iterates throug a named collection</info>


    <attribute>
      <name>collectionName</name>
        <required>true</required>
    </attribute>

    <attribute>
      <name>elementName</name>
      <required>true</required>
    </attribute>
  </tag>
</taglib>

***********************************************************
And finally, here's my JSP...

<HTML>
  <HEAD>
    <TITLE>Iterator Example</TITLE>
  </HEAD>
 <%@ page import="java.util.*" %>
<%@ taglib uri="taglib/iterate.tld" prefix="carman" %>

<%
        final String[] listElements = new String[] { "Hello", "World", "How",
"Are", "You" };
        final List list = Arrays.asList( listElements );
        request.setAttribute( "list", list );
%>
  <BODY>
  Before Tag!<BR>
    <carman:iterate collectionName="list" elementName="element">
      The current element is <%=request.getAttribute( "element" )%><BR>
    </carman:iterate>
  After Tag!<BR>
  </BODY>
</HTML>

Reply via email to