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).
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).
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!
posted 15 years ago
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 ]
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.
This tag is used in the page as
<%@ taglib prefix="mytag" uri="/WEB-INF/tld/taglib.tld" %>
<%="Welcome to my home"%>
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 ???