• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ - Custom Tag Development - Question 12 (Page 564)

 
Mauricio Andrade
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is true about the lifecycle of a Simple tag? (Choose all that apply.)

A. The release method is called after the doTag method.

B. The setJspBody method is always called before the doTag method.

C. The setParent and setJspContext methods are called immediately before the tag attributes are set.

D. The JspFragment of the tagBody is invoked by the Container before the tag handler's doTag method is called. This Value, a BodyContent object, is passed to the tag handler using the setJspBody method.



Answer: C.
- Option D is invalid because the fragment is invoked by the doTag implementation, NOT before the doTag is called.


But, according to the page 506 (lifecycle) the setJSPBody(JspFragment), when called, is called before the doTag method.
 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the option D is not wrong because of order of invocation, but i belive it's wrong becasue of the argument described for setJspBody method

From Specs
public void setJspBody(JspFragment jspBody)
Provides the body of this tag as a JspFragment object, able to be invoked zero or more times by the tag handler.
This method is invoked by the JSP page implementation object prior to
doTag(). If the action element is empty in the page, this method is not called at all.
Parameters:
jspBody - The fragment encapsulating the body of this tag.
 
Mauricio Andrade
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean, the BodyContent type is wrong?
 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i guess so....as per specs...
 
Kiaama Liames
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BodyTag class acquire the text and code inside their JSP pages by invoking getBodyContent(). This returns a BodyContent object that can be converted into a string or a reader these options are not available with SimpleTags. If you want to access the body in case of a SimpleTags the getJspBody() will return a JspFragment.
 
Pallavi ch
Ranch Hand
Posts: 76
 
Mauricio Andrade
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lavanya I already answerd your post. I hope it helped.

Fellows, I want to make sure I got it. The key point then is: JspFragment is not a BodyContent, right?

So, the explanation for the problem in option D) is the type BodyContent is not passed to getJspBody().

Any comments?

Regards,

Mauricio.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic