Question 12 : Wich is true about the lifecycle of a Simple tag?
answer D: The JspFragment of the tag body is invoked by the Container before the tag handler's doTag method is called. This Value, a BodyContent object, is passed to the tahe handler using setJspBody method.
I think D is a correct answer. But the book says it is wrong. The reason is " Option D is invalid becuase the fragment is invokde by the doTag implementation, NOT before doTag is called."
I check the lifecycle of the simeple Tag in JSP 2.4(pg. 2-81) and the HSF book(pg. 506). The JspFragment is invoked by setJspBody method before doTag(). Where am I wrong here?
posted 12 years ago
Let's see if we can tease-out the truth here...
setJspBody does pass a JspFragment to the tag handler, but only if there is a body. So already there's a bit of a problem since nowhere does it say "can" or "may" or "sometimes" or "if a body exists".
When I saw this question, I just blew past it without all of that thought because I figured that in my doTag implementation, I'm the one that gets the JspFragment if I want it (using getJspBody) and then call .invoke(null) on it. But someone has to set the JspBody (I didn't think about that). So for my experience on this question, it was 'dumb luck' that I got it right.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads