tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Switch" <switch200...@yahoo.es>
Subject Could this be a Tag Libs implementation bug?
Date Tue, 04 Feb 2003 10:09:53 GMT
Hello everybody.

I've just signed up this list, then I must present myselft first.
My name is Paco. I'm a J2EE developer for a local SW copany at Balearic
Islands (Spain - Europe).

I apologize me for my english. I write as well as I can :-)
I've read the etiquette and I've read the FAQ and I've read the mail
archieve, without having found an explanation to my problem.

Here it goes:

I've developed a small "iterate" TagLib. This Tag Lib works fine with WL and
Oracle iAS and I'm currently migrating to jboss + tomcat.

At the end of this e-mail I'will paste some code to explain properly why I
think there's a bug.
I've created a very simple JSP that tests my "IterateTag" and I get a
"NullPointerException" because of the EVAL_BODY_INCLUDE returned by
doStartTag.

I've been looking ".java" generated file from ".jsp" and I can see this
piece of code:

 int _jspx_eval_bit_iterate_0 = _jspx_th_bit_iterate_0.doStartTag();
 if (_jspx_eval_bit_iterate_0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
   String str = null;
   if (_jspx_eval_bit_iterate_0 !=
javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE) {
     javax.servlet.jsp.tagext.BodyContent _bc = pageContext.pushBody();
     _bc.clear();
     out = _bc;
     _jspx_th_bit_iterate_0.setBodyContent(_bc);
     _jspx_th_bit_iterate_0.doInitBody();
     str = (String) pageContext.findAttribute("str");
   }
   do {
     ...
     if (evalDoAfterBody !=
javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
       break;
   } while (true);
   if (_jspx_eval_bit_iterate_0 !=
javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE)
     out = pageContext.popBody();
 }

I can't undestand why this generated ".java" file executes "if !=
EVAL_BODY_INCLUDE" and I think it should be "if == EVAL_BODY_INCLUDE" (May
be I'm wrong).

I've read the following at J2EE 1.3 javadoc about BodyTagSupport class
(http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/jsp/tagext/Tag.
html#EVAL_BODY_INCLUDE):

EVAL_BODY_INCLUDE
public static final int EVAL_BODY_INCLUDE

Evaluate body into existing out stream. Valid return value for doStartTag

I can workarround this by returning EVAL_BODY_BUFFERED (so this isn't a
critical error)

Could anybody explain why is _jspx_eval_bit_iterate_0 being compared to be
not EVAL_BODY_INCLUDE?

Tell me if you need something else.

Thanks in advance for your help.


Some source code for "ItareateTag.java"
---
public int doStartTag() throws JspTagException
  {
    if(iterator==null) return SKIP_BODY;
    if(iterator.hasNext())
    {
      pageContext.setAttribute(name,iterator.next(),PageContext.PAGE_SCOPE);
      Enumeration en =
pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE);
      while (en.hasMoreElements()) System.out.println("Attributute: " +
en.nextElement());
      return EVAL_BODY_INCLUDE;
    }
    else return SKIP_BODY;
  }

  public int doAfterBody() throws JspTagException
  {
    System.out.println("IterateTag.doAfterBody. name: " + name + "
Iteratior: " + iterator + "Type: " + type);
    if(iterator.hasNext())
    {
      pageContext.setAttribute(name,iterator.next(),PageContext.PAGE_SCOPE);
      return EVAL_BODY_AGAIN;
    }
    else
    {
      return SKIP_BODY;
    }
  }

  public int doEndTag() throws JspTagException
  {
    System.out.println("IterateTag.doEndTag. name: " + name + " Iteratior: "
+ iterator + "Type: " + type);
    try
    {
      if(bodyContent != null)
        bodyContent.writeOut(bodyContent.getEnclosingWriter());
    }
    catch(java.io.IOException e)
    {
      throw new JspTagException("IO Error: " + e.getMessage());
    }
    System.out.println("Fin IterateTag.doEndTag. ");
    return EVAL_PAGE;
  }
---

Some source code for a JSP test file:
---
<%@ page contentType="text/html;charset=ISO-8859-15"%>
<%@ page import="java.util.*" %>
<%@ taglib uri="mytags" prefix="bit" %>
<%
  Vector v = new Vector();
  v.addElement("First Element");
  v.addElement("Second Element");
  v.addElement("Third Element");
  v.addElement("Fourth Element");
%>
<html>
  <head></head>
  <body>
    <table>
      <bit:iterate name="str" collection="<%=v%>" type="String">
        <tr><td>This items contains <%=str.length()%> characters and its
value is <%=str%></td></tr>
      </bit:iterate>
    </table>
</body>
---

taglib.tld contents:
---
<?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">
<taglib>
	<tlibversion>1.0</tlibversion>
	<jspversion>1.1</jspversion>
	<shortname>test</shortname>
	<uri></uri>
	<info>Iterate Tag Lib.</info>
      <tag>
		<name>iterate</name>
		<tagclass>es.caib.dembs.tags.IterateTag</tagclass>
		<teiclass>es.caib.dembs.tags.IterateTEI</teiclass>
		<bodycontent>JSP</bodycontent>
		<info>a simple iterator</info>
		<attribute>
			<name>collection</name>
			<required>true</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>name</name>
			<required>true</required>
		</attribute>
		<attribute>
			<name>type</name>
			<required>true</required>
		</attribute>
	</tag>
</taglib>
---

___________________________________________________
Yahoo! Móviles
Personaliza tu móvil con tu logo y melodía favorito 
en http://moviles.yahoo.es

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message