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

Tag Handler question

 
Ronan Dowd
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was going through some sample questions for the SCWCD and happened upon the below

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>
Hello
</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 answer given is 4. Is this correct? I know that 'Hello' does get printed as doStartTag returns the correct value, but why isn't the text 'how are you?' also printed ?

Any thoughts would be great.
Cheers - Ro
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2535
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ronan,

Please make sure that you QuoteYourSources when posting a mock question

The correct answer should be 2) The jsp page will print Hello how are you? when you have a taglib declaration on the
JSP that is using this tag. (Hello is printed by the body-evaluation and after the body is evaluated it will print the text from the doAfterBody() method.)

As this taglib declaration is not included in the part of the JSP they are showing you can conclude it is not there and only Hello will be printed as template text

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic