Forums Register Login

<body-content> "empty" still allowing content

+Pie Number of slices to send: Send
Hi,

I have been trying to figure out why the following situation is arising in <body-content>empty</body-content>. If I provide the entry in tld then specifying a content in the body of the tag should give an exception, but it's working smoothly in my case. Please see the following snippets:

Code from the tld:

<tag>
<name>advice</name>
<tag-class>com.example.AdvisorTagHandler</tag-class>
<body-content>empty</body-content>
<attribute>
<name>user</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

Code from the tag handler:

public void doTag() throws JspException, IOException{
getJspBody().invoke(null);
}

Code from the jsp using tag:

<mine:advice>
Content should not print...
</mine:advice>

When I debug the tag handler, getJspBody() does not return null. I am using Tomcat 6.0. Is it container specific property? Please help, this trivial issue has taken my lot of time.

+Pie Number of slices to send: Send
I don't know your answer but you have asserted that attribute is required in tld,but are not providing one in the tag.
+Pie Number of slices to send: Send
Sorry for the mistake. My container is ignoring all the body-content settings and taking 'scriptless' as the value. I know for tomcat the default is 'JSP' for tags, but I'm not sure why this behavior is occurring. Thanks for your reply. I will update with my findings.
+Pie Number of slices to send: Send
I can't answer about error in your container but as far as I know JSP is not the default for any of the tags
and in simple tags JSP are not allowed in body as the body content of JSPFragment does not support scriptlets.
check this faq link .
webpage
+Pie Number of slices to send: Send
I'm getting this problem as well and its driving me nuts. Either I completely misunderstand what a body-content of empty is meant to do, or there is a bug in my container implementation (Tomcat 6.0.18 on Linux).

I am expecting to see an error message when the second tag is encountered in the JSPX since the tag supplies a body, yet the TLD says "empty" for body-content. However my container is writing out the tag body regardless.


Here are the relevant files if someone would care to verify for me - maybe there is a really obvious mistake I've made below???


TestBodyContentEmptyBug.jspx



TestBodyContentEmptyBug.tld



TestBodyContentEmptyBug.java



Filename web.xml



Here is what my WAR file looks like:



J
+Pie Number of slices to send: Send
Yes,same result in Tomcat 5.5.9 too.Output of your code is

About to call TestBodyContentEmptyBug...Done calling TestBodyContentEmptyBug...
--------------------------------------------------------------------------------
About to call TestBodyContentEmptyBug with a body...
Hello from the body of TestBodyContentEmptyBug... this body should cause an error... should it not?
Done calling TestBodyContentEmptyBug...
--------------------------------------------------------------------------------



But i remember testing similar program in case of simple tags on tomcat 6.0.18.And exception was raised there (i think) when tld declared the body content to be empty and i passed body in the invocation of tag.
Did you test for simple tags too?
+Pie Number of slices to send: Send
Hi,

Thanks for the replies so far - I've got a little further with this problem now.

It seems that it only happens with JSP Documents and not with JSP Pages.

So when I convert my TestBodyContentEmptyBug.jspx JSP Document to TestBodyContentEmptyBug.jsp JSP Page , the container successfully throws the expected error:

Filename TestBodyContentEmptyBug.jsp




The error message seen in the browser:




So - can anyone tell me why this is? Why would a JSP Document behave differently than a JSP Page with regard to body-content?

Cheers,

J
+Pie Number of slices to send: Send
I see you've filed this as a bug in Tomcat: body-content of empty in TLD ignored for JSP Documents. That's probably the best move. I imagine this is an oversight in the JSP document translator, since the container can't enforce the "empty" content by XML schemas but instead has to do it programmatically at translation time, and I guess that test is missing in the translation engine. You could also try this on non-Tomcat containers (e.g. Caucho Resin) and see what behaviour that gives.
+Pie Number of slices to send: Send
Hi,

Yes I posted the bug this morning - so we'll see if an answer comes back on that.

I have the Sun GlassFish Enterprise v2.1 installed as well, but unfortunately this uses Tomcat code at the back end and so exhibits the same behavior!

I'll see what other containers I can get hold of then, and try them.

Cheers,

J
+Pie Number of slices to send: Send
Hi,

Further update.

I just tried this in Caucho Resin (http://www.caucho.com/) and both JSP Pages and Documents throw an error as expected.

So it looks like it is a problem in Tomcat.

Output from Caucho Resin below:



Filename TestBodyContentEmptyBug.jsp



Filename TestBodyContentEmptyBug.jspx



Cheers,

J
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2218 times.
Similar Threads
SimpleTagSupport class
TLD files variable element
query
Doubt in jsp:attribute
Question on Empty body content of Simple Tag Handlers
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:20:59.