Could this be a Tag Libs implementation bug?

2003-02-04 Thread Switch
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
trtdThis 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
tlibversion1.0/tlibversion
jspversion1.1/jspversion
shortnametest/shortname
uri/uri
infoIterate Tag Lib./info
  tag
nameiterate/name
tagclasses.caib.dembs.tags.IterateTag/tagclass
teiclasses.caib.dembs.tags.IterateTEI/teiclass
bodycontentJSP/bodycontent
infoa simple iterator/info
attribute
namecollection/name
requiredtrue/required
rtexprvaluetrue/rtexprvalue
/attribute
attribute
   

RE: Could this be a Tag Libs implementation bug?

2003-02-04 Thread Barney Hamish
Have you considered using the struts logic tags
(http://jakarta.apache.org/struts/index.html) or the JSTL
(http://jakarta.apache.org/taglibs/index.html) rather than implementing this
stuff yourself? There are some useful custom tags (like the iterate tag
you're trying to implement).
Hamish

 -Original Message-
 From: Switch [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, February 04, 2003 11:10 AM
 To: Tomcat User Group
 Subject: Could this be a Tag Libs implementation bug?
 
 
 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/j
 sp/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
 trtdThis 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

RE: Could this be a Tag Libs implementation bug?

2003-02-04 Thread Switch
 From: Barney Hamish
 To: 'Tomcat Users List'
 Subject: RE: Could this be a Tag Libs implementation bug?

Hi Hamish, thanks for your response.

 Have you considered using the struts logic tags
 (http://jakarta.apache.org/struts/index.html) or the JSTL
 (http://jakarta.apache.org/taglibs/index.html) rather than
 implementing this
 stuff yourself? There are some useful custom tags (like the iterate tag
 you're trying to implement).

Oh! Yes. I'm currently using some of them. The IterateTag I've pasted is a
test to reproduce a problem.
My TagLibs generated NullPointerException with JBoss and I wrote some very
simple files to post it here. So, if they were a bug, it would be easier for
developer to path it.

Thanks for the idea.

 Hamish

  -Original Message-
  From: Switch
  Sent: Tuesday, February 04, 2003 11:10 AM
  To: Tomcat User Group
  Subject: Could this be a Tag Libs implementation bug?
 
 
  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

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

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]