Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

output of custom tag extending BodyTagSupport class

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
viswanath sastry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iam not getting any output even if i return EVAL_BODY_BUFFERED in my doStartTag method or remove doStartTag method.
 
viswanath sastry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doStartTag must indicate whether to evaluate the body. Try this:
public int doStartTag() throws JspException
{
return EVAL_BODY_TAG;
}
 
viswanath sastry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
What are you doing? You are supposed to be reading this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic