Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tagdependent value for the body-content element

 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
I have found such assertion:
If the <body-content> element's value is tagdependent, the tag handler class must implement the BodyTag interface.
Is this true? If so, why can't I implement IterationTag (or extends TagSupport).

Thanks.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Serghei Jelauc:
Hi all.
I have found such assertion:
If the <body-content> element's value is tagdependent, the tag handler class must implement the BodyTag interface.
Is this true? If so, why can't I implement IterationTag (or extends TagSupport).

Thanks.


There are 3 different types of content or text that you could expect in a custom tag.(classic style)

<mycustomTag>
XXXXX
</mycustomTag>

Where XXXXX could be

a. empty
b. JSP Content (valid JSP scriptlets or html etc that can be evaluated by the JSP Container)
c. Special Content(which is not supposed to be evaluated or interpreted by the JSP Container).(You the tag developer would like to manipulate its contents)

Depending on your purpose, you decide what kind of tag to write and the class to implement the tag.

If the idea is to interpret the contents of the body inside the custom tag, then you set body-content = tagdependent in the tld file and either implement BodyTag interface or extend the BodyTagSupport class which implements the BodyTag interface. Extending the BodyTagSupport class is a lot easier and recommended!

One example of the Special Content would be :

<mycustomTag>
SELECT * FROM employee where age > 30
</mycustomTag>

Perhaps an SQL Query string that you would like to manipulate inside the tag and do not want the JSP Container to evaluate it.(If it evaluates, it would consider it to be some template html text!)

I do not know what happens when you set the body-content to tagdependent and extend TagSupport(IterationTag interface). Perhaps, you may get deployment errors or runtime errors. But it isn't logical, isn't it?
Your implementation has to be consistent with your objective

BTW, we need to study Simple Tags also for the exam. That is a different story!
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishwa.
Thanks a lot. Now it is more clear for me.
But after I tryed to create a small app. I have one more Question.

Here the tag handler class:


If I use
<myTag:test>
SELECT * FROM TABLE;
</myTag:test>

the result is:
in the doStartTag()
in the doEndTag()

it looks like doAfterBody does not work.
BUT if I change the tag handler code like this:

that is OK.
I can't understand WHY?
[ May 17, 2005: Message edited by: Serghei Jelauc ]
 
Bhumika Thakkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not necessary that body-content of tagdependent would mean BodyTag. Tag and TagSupport does have an option to set the body-content to tagdependent.
Even simpleTags can have body-content set to tagdependent and they too can't modify the body.
 
trivikram Kumar
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If its an SQL qewry.it works if body-content is set as tagdependent as to my knowledge...
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bhumika Thakkar:
Tag and TagSupport does have an option to set the body-content to tagdependent.


Are you sure?...Is it mentioned in the HF book? :roll:
 
Bhumika Thakkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, Its mentioned in HFS and Hanumant Deshmukhs books...
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bhumika Thakkar:
Yup, Its mentioned in HFS and Hanumant Deshmukhs books...


Sorry Bhumika, I am confused. Could you please mention the page numbers in both the books? I wonder in that case what the benefit would be for the Tag handler.

My understanding is that TagSupport's doStartTag() returns either

1. SKIP_BODY = to ignore the body contents
2. EVAL_BODY_INCLUDE = to allow the container to evaluate/execute the contents

Only BodyTagSupport has the special capability to interpret the contents.(body-content = tagdependent)

Would appreciate if you could explain further.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhumika,
Just to be more clear on my question:

I understand that we can have body-content=tagdependent for Tag files(JSP2.0) when we declare the tag directive to include tag header files.
example:
<% tag body-content="tagdependent" %>

But I am not sure about the classic Tag Handler, TagSupport.
When can it have body-content=tagdepedent set in the TLD?

 
Moussa Kecibi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

Marks: 1 A Simple tag PrintMsg extends SimpleTagSupport and uses the following descriptor in its tag library descriptor:

<tag>

<name>PrintMsg</name>
<tag-class>customtags.PrintMsg</tag-class>
<attribute>

<name>msg</name>
<requried>false</requried>
<rtexprvalue>false</rtexprvalue>

</attribute>

</tag>

This tag is used in the page as
//Test.jsp
<%@ taglib prefix="mytag" uri="/WEB-INF/tld/taglib.tld" %>
<mytag:PrintMsg>
<%="Welcome to my home"%>
</mytag:PrintMsg>


Which of the following statements is true about this tag. Select two choices.
Choose at least one answer. a. The body content of the content cannot contain scripting code.
b. The message "Welcome to my home" is printed.
c. The tag library should be placed in /WEB-INF/tags directory.
d. The body content of the tag can contain template text.
e. The attribute "msg" is missing and hence the compilation fails.

Can anyone tell me which one in the good answer (the pb there is no <body-content> Tag defined ???) whizelabs said the good answer is a and d ???
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Can you start a new thread when you want to ask something ? There's no reason to post a question in that 5 years old thread.
2. Where does this question come from ? QuoteYourSources.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic