• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doAfterBody()

 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a question:-

Given the following tag handler defined with <bodycontent>JSP</bodycontent>

public class body extends TagSupport {
public int doStartTag() throws JspException{
return EVAL_BODY_INCLUDE;
}
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 ans is 4.The jsp page will print Hello

1.Why is "how are u" not getting printed??
2.If i extend BodyTagSupport then when i have to print something from inside doAfterBody() , do i have to use getBodyContent.getEnclosingWriter() ???
I am a lot confused in custom tags.If there is a good link for it, please let me know.

thanks,mallika
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doAfterBody() will be invoked if doStartTag() returns EVAL_BODY_BUFFERED.
 
Rajitha Arun
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mallika,

Did you work this example out? The answer should be choice 2.

Satou,

doAfterBody() will also be invoked if the return is EVAL_BODY_INCLUDE. Isn't? EVAL_BODY_BUFFERED is for doInitBody(). 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
doAfterBody() will also be invoked if the return is EVAL_BODY_INCLUDE. Isn't?

Yes, sorry, I messed up that one, forget about my post.
Thank you for pointing this out.
 
Clifton Eaton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran this last night, and the output was "Hello How are you". seems like number 2 is correct. Where did this question come from?
 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this question was ( actually i dont remember now) but guesss was in JPilot mock simulator..

so whats the correct ans..is it Hello OR hello, How are you?

mallika
 
Rajitha Arun
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is "hello how are you".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic