Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF Custom Tag question

 
Sandy Shah
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With reference to the HF book, the answer to question 9 at the bottom of chapter 10 (page 553) looks incorrect to me. If you agree with the book, can you please post a better explanation? Thanks.

Given:
10. public class BugTag extends BodyTagSupport {
11. public int doStartTag() throws JSPException {
12 // insert code here
13. }
14. }

Assume that the tag has been properly configured to allow body content. Which, if inserted at line 12 would cause the JSP code
<mytags:mytag>BodyContent</mytags:mytag> to output BodyContent>

The book marks the correct answer to be
B. return EVAL_BODY_INCLUDE;
and tells you that option C is invalid because it directs the body of the tag to a buffer which the tag does not process. ??

However, since the class is extending BodyTagSupport, the correct answer should be: (ref to page 536)
B. return EVAL_BODY_INCLUDE;
C. return EVAL_BODY_BUFFERED;
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandy, Not to worry!

In the real exam, you will have 'choose 1' (or) 'choose 2'.

Give first priority to EVAL_BODY_INCLUDE because that is simple to use.

However, if we use EVAL_BODY_BUFFERED, then we have to explicitly output the body content using writeOut and getEnclosingWriter methods.

But as you say, we can use both to output the body content.
 
Mylene Reiners
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EVAL_BODY_BUFFERED

Request the creation of new buffer, a BodyContent on which to evaluate the body of this tag. Returned from doStartTag when it implements BodyTag. This is an illegal return value for doStartTag when the class does not implement BodyTag.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returning EVAL_BODY_BUFFERED won't print BodyContent to the output because this class only overrides the doStartTag() method and none of the rest....therefore the Question is perfectly alright
[ December 28, 2006: Message edited by: Sayak Banerjee ]
 
Sandy Shah
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for those who responded and helped clarify the issue. I now have a better understanding of buffered body content.

Sandy
 
Renu Radhika
Ranch Hand
Posts: 243
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Sayak.The class is extending BodyTagSupport and not BodyTag which will have the default implementation of setBodyContent(BodyContent b),so both should be fine right?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic