my dog learned polymorphism
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HF Custom Tag question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HF Custom Tag question" Watch "HF Custom Tag question" New topic

HF Custom Tag question

Sandy Shah

Joined: Dec 27, 2006
Posts: 2
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.

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
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)
Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
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.

Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
Mylene Reiners

Joined: Apr 08, 2004
Posts: 7

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

Joined: Nov 28, 2006
Posts: 292
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 ]

Turn on, tune in, drop out.
Sandy Shah

Joined: Dec 27, 2006
Posts: 2
Thanks for those who responded and helped clarify the issue. I now have a better understanding of buffered body content.

Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
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?
I agree. Here's the link:
subject: HF Custom Tag question
It's not a secret anymore!