• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ - Custom Tag Development - Question 17 (Page 567)

 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I think I did not get well the stuff presented on page 472 of this book regarding the <body-content> element.

I know there are four types of values allowed in this element :

<body-content>empty</body-content>
<body-content>scriptless</body-content>
<body-content>tagdependent</body-content>
<body-content>JSP</body-content>

However, when I saw the question below I got quite confused.

Given a tag, simpleTag, whose handler is implemented using the Sample tag model and a tag, complexTag, whose handler is implemented using the Classic tag model.

Both tags are declared to be non-empty in the TLD.

Which JSP code snippets are valid uses of this tag ?


According to answer gave by authors, B and D options are incorrect because both have scripting code in it.

My question is : If I can declare both tags in TLD by putting
<body-content>JSP</body-content> in <body-content> element which allows the tag have anything that goes inside a JSP, why options B and D are incorrect ?
 
navat venu
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both tags are declared to be non-empty in the TLD.


According to the "HFSJ errata" above sentence should be corrected as
"Both tags are declared to be non-empty and non-tag dependent in the TLD"

The left-out options are body contents can be "JSP" or "Scriptless".
Options 'B' and 'D' are wrong because the tags contains scriptlet and expression.
---------------------------------------------------------------------------
But if you declare body-content of the tag as only "JSP" options 'B' and 'D' are correct since 'scriptlet and expression' can go inside a JSP.

Please correct me if i am wrong !!
 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple tag doesn't have JSP as the valid <body-content> type

From Specs

The body of a Simple Tag, if present, is translated into a JSP Fragment and
passed to the setJspBody method. The tag can then execute the fragment as many times as needed. See Section JSP.7.1.6 for more details on JSP Fragments. Because JSP fragments do not support scriptlets, the <body-content> of a SimpleTag cannot be �JSP�. A TLD is invalid if it specifies �JSP� as the value for <body-content> for a tag whose handler implements the SimpleTag interface. JSP containers are recommended to but not required to produce an error if �JSP� is specified in this case.
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Navat & Mohd,

Thanks for your prompt replies.

So Navat, your explanation above truly explains why option B is incorrect. Thanks a lot.

However, I'm still in doubt why option D is incorrect ? Doesn't classic tags also support the element type <body-content>JSP</body-content> in TLD ?

I looked at specs and could not find anything that blocks classic tags from using <body-content>JSP</body-content>

Could you please clarify it better for classic tags as well ?
 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess validation of body content of tag take place at translation time and at that time anything in between tag is the tag body.

Although JSP is valid body-content of classic tag, but during translation time it's part of body of simple tag (indide classric tag body as classic tag is also in body of simple tag), hence will throw an error like

Scripting elements ( <%!, <jsp eclaration, <%=, <jsp:expression, <%, <jsp:scriptlet ) are disallowed here.


Hope it helps
[ September 11, 2006: Message edited by: Mohd Fuzail ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic