aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Enthuware doubt 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 "Enthuware doubt" Watch "Enthuware doubt" New topic
Author

Enthuware doubt

Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 326

Given:

<%@ taglib uri="example" prefix="example" %>
<example:aTagWithBody>
<%="Body Content"%>
</example:aTagWithBody>

If the aTagWithBody handler extends from TagSupport and returns BodyTag.EVAL_BODY_BUFFERED from doStartTag(), what will the above page print?

A) Tag Handler will not compile
B) An Exception at request time
C) "Body Content" will NOT be printed
D) "Body Content" will be printed
E) None of these

I think it should be A because the constant BodyTag.EVAL_BODY_BUFFERED is not available in TagSupport (see API) but the answer given is:

"It will compile because the compiler only checks whether the doStartTag() is returning an int or not. It does not check whether the int value is valid or not."

Explanation:
"At request time, the container validates the return value of the doStartTag() methods. In this case, since the Tag handler extends from TagSupport, it does not implement BodyTag interface and so it cannot return BodyTag.EVAL_BODY_BUFFERED from the doStartTag() method. The behavior of the container, in such as case, is undefined. One container may cause a ServletException to be thrown from the JSP page and another may just ignore it.

However, the tag can be coded to return BodyTag.EVAL_BODY_BUFFERED without any compile time error because the compiler does not have any knowledge of what this tag is allowed to return."

This explanation seems to be saying that the compiler will not check that this constant exists! Is this correct? I have my exam in 1 hour.....
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1674
    
  25

Hi Will,

This explanation seems to be saying that the compiler will not check that this constant exists! Is this correct?

Yes it is correct! The compiler only checks whether a int is returned from the method (not whether that value is allowed in this context).

Have a quick look at:
doStartTag question

Goog luck with your exam!!

Regards,
Frits
Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 326

Hi Frits,
The constant doesn't exist so how can you return it? How does the compiler know that this is even an int?

The only constants available are:
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE and EVAL_BODY_AGAIN
Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 326

Aaahhh, I'm being real dumb aren't I! I see what's going on here.....
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1674
    
  25

ok

These are really trick questions, you won't get something like this on the exam.

Regards,
Frits
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

I would say you can get such a question on the exam. Some exam question are really really tricky. In my SCWCD exam I got one question where the question asked for 2 correct answers but I thought 3 answers were correct. It took me 10 minutes to figure out that single question...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enthuware doubt