permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes tagdependent value for the body-content element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "tagdependent value for the body-content element" Watch "tagdependent value for the body-content element" New topic
Author

tagdependent value for the body-content element

Serghei Jelauc
Ranch Hand

Joined: Jul 24, 2002
Posts: 128
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.


SCJP 1.4 <br />SCBCD 1.3<br />SCWCD 1.4
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
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

Joined: Jul 24, 2002
Posts: 128
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

Joined: Apr 18, 2005
Posts: 79
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.


SCBCD (Preparing) <br />SCWCD, 82%<br />SCJP, 90%
trivikram Kumar
Ranch Hand

Joined: Feb 21, 2005
Posts: 172
If its an SQL qewry.it works if body-content is set as tagdependent as to my knowledge...


Javainn<br /> <br />SCJP,SCWCD,SCBCD,<br />ICED (IBM-287,IBM-484,IBM-486)
IBM certified in DB2 V 8.1 Family Fundamentals (IBM 700)
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
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

Joined: Apr 18, 2005
Posts: 79
Yup, Its mentioned in HFS and Hanumant Deshmukhs books...
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
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

Joined: Aug 27, 2003
Posts: 1064
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

Joined: Oct 31, 2009
Posts: 13
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
 
 
subject: tagdependent value for the body-content element
 
Similar Threads
Is the scriptlet illegal for simple Tag even if the body-content is set to tagdepende
BodyTag Interface doubt
not getting the EL
body-content value??
body-content of tag directive in Tag File