Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Tag Handler question..  RSS feed

 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following tag handler defined with <bodycontent>JSP</bodycontent>

public class body extends BodyTagSupport {
public int doAfterBody() throws JspException {
try { pageContext.getOut().print("how are you?"); }catch(IOException e) {}
return SKIP_BODY;
}
}

what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>

1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello


The given ans : 4
But my ans : It prints nothing. (As there is no doStartTag)..

Please throw some light on this, as to what should be the right ans..and how??

thanks,
mallika
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about this..

What is the 'default' return value for doStartBody when you extend BodyTagSupport ?

EVAL_BODY_BUFFERED right?

That means it evaluates the body and goes to the doAfterBody

correct me if i am wrong.
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't print anything, because doStartTag's default return value is EVAL_BODY_BUFFERED. pageContext.getOut will return the buffer, not the page. As long as the buffer is not flushed, nothing will be shown on the client.
An overridden doStartTag returning EVAL_BODY_INCLUDE would be ok.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!