File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes output of custom tag extending BodyTagSupport class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "output of custom tag extending BodyTagSupport class" Watch "output of custom tag extending BodyTagSupport class" New topic
Author

output of custom tag extending BodyTagSupport class

viswanath sastry
Greenhorn

Joined: May 04, 2003
Posts: 24
i was trying out some examples on custom tags(BodyTagSupport class). Iam not able to understand the ouput.some one please make me understand the output.
=>NOTHING is printing in bodytagtest.jsp output. <=
Below, i give the relevent code.
----bodytagtest.java---
package sampleLib;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class bodytagtest extends BodyTagSupport {
public int doStartTag() throws JspException
{
return EVAL_BODY_INCLUDE;
}
public int doAfterBody() throws JspException {
try { pageContext.getOut().print("how are you?"); }catch(java.io.IOException e) {}
return SKIP_BODY;
}
}
---------------sampleLib.tld-------
<!-- bodytagtest TAG -->
<tag>
<name>bodytagtest</name>
<tag-class>sampleLib.bodytagtest</tag-class>
<body-content>JSP</body-content>
</tag>
------------bodytagtest.jsp--------
<%@ taglib uri="/WEB-INF/sampleLib.tld" prefix="bodytag" %>
<html><body>
<bodytag:bodytagtest>
<i>Hello hai </i>
</bodytag:bodytagtest>

</body></html>
---------------
Thanks.


visu
viswanath sastry
Greenhorn

Joined: May 04, 2003
Posts: 24
iam not getting any output even if i return EVAL_BODY_BUFFERED in my doStartTag method or remove doStartTag method.
viswanath sastry
Greenhorn

Joined: May 04, 2003
Posts: 24
i have stopped tomcat server and started it again and i am getting output as expected in cases that i described before.But i dont know what went wrong before.
anyways thanks.
Vineet Sharma
Greenhorn

Joined: Jan 08, 2003
Posts: 2
Try the following 3 lines instead of
pageContext.getOut().print("how are you?");
// Code Sample Begin
1 JSPWriter out = bodyContent.getEnclosingWriter() ;
2 out.print("how are you?") ;
3 bodyContent.writeOut(out);
The trick when using BodyTagSuport class is that you have to get a handle on the enclosing writer.
In this case the enclosing writer for the bodyContent object is the "out". However if you had 3 tags, child, parent and grandparent, you would have the bodyContent of child written to parent, that of parent written to grandparent and that of grandparent to the out. In this way, the buffer is not flushed.
For reference, each tag has it's own bodyContent object and before ending the tag, you have to write the Tag's content to the outer tag's bodyContent.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
doStartTag must indicate whether to evaluate the body. Try this:
public int doStartTag() throws JspException
{
return EVAL_BODY_TAG;
}


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
viswanath sastry
Greenhorn

Joined: May 04, 2003
Posts: 24
doStartTag must indicate whether to evaluate the body. Try this:
public int doStartTag() throws JspException
{
return EVAL_BODY_TAG;
}

EVAL_BODY_TAG is deprecated in jsp 1.2.There are EVAL_BODY_BUFFERED and EVAL_BODY_INCLUDE or EVAL_BODY_AGAIN now as the case may be.
 
jQuery in Action, 2nd edition
 
subject: output of custom tag extending BodyTagSupport class