Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HSF page 564 Question 12, answer D

 
Wai Iu
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks!

Waiyung
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".

The second, and I think bigger problem with "D" is that I think it's implying that a JspFragment is a BodyContent object, but javax.servlet.jsp.tagext.JspFragment extends java.lang.Object.

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.

--Dale--
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic