|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
I think it should be "c and e", since doAfterBody() will be called only if doStartTag() does not return SKIP_BODY (which means it either returns EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED).
But the question does not tell you which interface/class is the tag handler implementing/extending. When you call a class "tag handler", does it mean that it is implementing the Tag interface?
Assuming no exceptions occur, doAfterBody() is called after doStartTag() for any tag that implements IterationTag and returns EVAL_BODY_INCLUDE from doStartTag().
My question is - is this enough for the doAfterBody() to execute? Doesn't the tag itself has to be used with the body?
a body-content set to "scriptless" in the TLD
Tag handler can extend IterationTagSupport
implemented the doAfterBody() method,
doStartTag() method can return EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED
but the doAfterBody() won't be executed if I have something like:
<pedro:myClassicTag />
My result is:
Tag: START!
Tag: END!
Empty and Non-Empty Action
If the TagLibraryDescriptor file indicates that the action must always have an empty element body, by a <body-content> entry of "empty", then the doStartTag() method must return SKIP_BODY.
Note that which methods are invoked after the doStartTag() depends on both the return value and on if the custom action element is empty or not in the JSP page, not on how it's declared in the TLD.
If SKIP_BODY is returned the body is not evaluated, and then doEndTag() is invoked.
If EVAL_BODY_INCLUDE is returned, and the custom action element is not empty, the body is evaluated and "passed through" to the current out, then doAfterBody() is invoked and, after zero or more iterations, doEndTag() is invoked.
The result is:
Tag: START!
Tag: AFTER BODY!
Tag: END!
SCJP
SCJP
OCJP6
So is it correct, that answer E shouldn't be checked?
And if yes, why isn't it listed in the errata yet?
OCJP6
Well actually after thinking about it, Option E is correct.
Because if doAfterBody() is reached - which is the assumption of option E - returning EVAL_BODY_AGAIN will definitely let
doAfterBody() get invoked again.
Frits Walraven wrote:
But the question does not tell you which interface/class is the tag handler implementing/extending. When you call a class "tag handler", does it mean that it is implementing the Tag interface?
Not always, you have to look at the methods they are giving you in the question. In this question they are only mentioning doStartTag() and no doTag() so you question is only about the "Classic" Custom Tags. (which all implement the Tag interface though). The Simple Custom Tag, doesnot implement the Tag interface.
Regards,
Frits
Firstly the EVAL_BODY_INCLUDE is declared in "Tag" interface not the iterationtag interface.
Can you now say the answer to this question?
It can be c) as well as e)
Consider Paul's rocket mass heater. |