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

JSP or TagDependant

 
Hema Nandhini
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This question is from Marcus Green's Mock Exam:

You've developed a tag that can fire SQL queries. The query should be specified as the body of the tag. What should be the value of <body-content> for this tag's taglib descriptor?

Select 1 correct option.
a sql
b JSP
c text
d tagdependent

Answer is "d"

But, according to me, b can also be a correct answer because we might need dynamic values to be evaluated to form the query. Please share your thoughts on this

Thanks
Hema

[ August 17, 2008: Message edited by: Hema Nandhini ]
[ August 17, 2008: Message edited by: Hema Nandhini ]
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the tag extends SimpleTagSupport the <body-content> cannot be JSP.


So d is the choice for all type tags.


Thanks and Regards
Joy
 
Hema Nandhini
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joy, got it..
 
ch praveen kumar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joy Mukherjee:
If the tag extends SimpleTagSupport the <body-content> cannot be JSP.


So d is the choice for all type tags.


Thanks and Regards
Joy




Hi Joy,could you please tell me the reason behind this.. because a simple tag <body-content> can accept "empty","scriptless","JSP","tagdependent". but you are saying that it cannot be JSP,could you tell me in which scenario it happens...


with regards
Praveen ch
 
Rufus Addis
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praveen kumar ch:

.. because a simple tag <body-content> can accept "empty","scriptless","JSP","tagdependent". but you are saying that it cannot be JSP,could you tell me in which scenario it happens...


In essence a Simple Tag can't handle scriptlets in the body of the tag, so the container will throw an error when in encounters a JSP page that refers to a simple tag with a body-content set to "JSP" (or missing as the default value is also JSP).

From the JSP spec:

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.

Rufus.
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you found your own answer. The container will throw a error if you put JSP code inside the body content of Simple Tags

Thanks and Regards
Joy
 
ch praveen kumar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rufus Addis:


In essence a Simple Tag can't handle scriptlets in the body of the tag, so the container will throw an error when in encounters a JSP page that refers to a simple tag with a body-content set to "JSP" (or missing as the default value is also JSP).

From the JSP spec:

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.

Rufus.



Thanks for your valuable reply..
So instead of putting JSP as <body-content>,should I put tagdependent as <body-content>?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic