• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tag Handler question..

 
mallika shah
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
 
Krishna R Seelam
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.
 
Christophe Verré
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