Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with the following ques

 
Anonymous
Ranch Hand
Posts: 18944
  • 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 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
According to the answer..it still prints "Hello"
Why is this so???. As the doStart TAg method returns eval_body_include..should'nt it print hello how are u....
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the doAfterBody return of SKIP_BODY might answer the questions. Kind of a trick question there.
Mark
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok..
becoz doStartTag says eval_body_include it evaluates the body but there is a print statement in doAfterBody ..which comes before "return skip_body" then should'nt it print "how are u" and skip the body
This is still not clear..please explain
 
Goan Balchao
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See, the class dosen't extend BodyTagSupport or implement the BodyTag interface. So the container will not give a call to the doAfterBody() method of this object.
This method is just a user defined method for this class. So unless explicitly called by some other member of this class, it will never be called.
Hope that answers your question.
 
Goan Balchao
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See, the class dosen't extend BodyTagSupport or implement the BodyTag interface. So the container will not give a call to the doAfterBody() method of this object.
This method is just a user defined method for this class. So unless explicitly called by some other member of this class, it will never be called.
Hope that answers your question.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks hemanth
 
rganniram
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant accept Hemant answer.. If you extend TagSupport and return EVAL_BODY_INCLUDE it will be treated as IterationTag.
So doAfterBody() will be called.
Ganesh Ram
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"rganniram"-
Welcome to the JavaRanch!
Please adjust your displayed name to meet the JavaRanch Naming Policy.
You can change it here.
Thanks, and again welcome to the JavaRanch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic