• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enthuware doubt

 
Will Myers
Ranch Hand
Posts: 381
Java jQuery Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 2343
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 381
Java jQuery Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 381
Java jQuery Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaahhh, I'm being real dumb aren't I! I see what's going on here.....
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2343
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok

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

Regards,
Frits
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic