You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ryan Daigle <RD...@healthdec.com> on 2002/08/26 19:24:15 UTC
Tomcat 4.x body tags not exposing variables?
I'm having a problem with Tomcat 4.x and body tags. I am trying to migrate
from a JBoss/Tomcat4.x environment to a Tomcat 4.1.9 setup. I say this
because the tags in question function as I would expect with the JBoss setup
but not the Tomcat setup.
Here is the situation. I have a tag that exposes certain variables to the
page:
public class ExposerTag extends BodyTagSupport {
public int doStartTag() throws JspTagException {
//This "team" variable is properly declared in a TEI class
pageContext.setAttribute("team", team);
return EVAL_BODY_INCLUDE;
}
}
And I call this tag as such within a jsp page:
<softball:softballExposer>
<%= team.toString(); %>
</softball:softballExposer>
I get a NullPointer exception from this JSP page at the "team.toString()"
line. I know from logging statements within the tag that there is a valid
Team object being sent to the page context.
Taking a look at the resulting servlet source of this jsp page, it looks
like that because the tag returns the EVAL_BODY_INCLUDE result, the team
attribute is never set (the code has been cleaned for your viewing
pleasure):
int result = exposer.doStartTag();
if (result != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
if (result != javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE) {
javax.servlet.jsp.tagext.BodyContent _bc =
pageContext.pushBody();
_bc.clear();
out = _bc;
exposer.setBodyContent(_bc);
exposer.doInitBody();
team = (Team) pageContext.findAttribute("team");
}
do {
out.write(team.toString());
} while {
//blah....
}
}
So I believe my problem is that because I am using the EVAL_BODY_INCLUDE
result for the doStartTag() method of my exposer tag, the attribute is never
sent to the page context for consumption within the page.
My questions are; 1) Why would this work in a JBoss/Tomcat setup and not in
a purely Tomcat setup and 2) Should I not be using the EVAL_BODY_INCLUDE
result code for a method of this type?
When I change the tag to return the EVAL_BODY_BUFFERED result, then any
nested tags are properly written out to the output stream, so I don't
believe this is an acceptable option.
Can anybody shed some light on my situation. I have that eerie feeling that
I'm missing something incredibly simple here...
-Ryan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>