File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes <jsp:doBody> tag not displaying scriptlet as template text when the body content is tagdependent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "<jsp:doBody> tag not displaying scriptlet as template text when the body content is tagdependent" Watch "<jsp:doBody> tag not displaying scriptlet as template text when the body content is tagdependent" New topic
Author

<jsp:doBody> tag not displaying scriptlet as template text when the body content is tagdependent

Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Hi

I am preparing for the SCWCD exam and working on jsp tag file where i have some doubts.

here is my code :

Jsp:



Tag file :


When i runt the file,it displays the EL as template text but scriptlets and the action tags are simply ignored and not even displayed as template text or not even evaluated which is right.

But why they are not displayed?

When i see th generated HTML source code,they are there as template text.

In IE8 only EL is displayed but in Mozilla only EL and expressions are displayed.

See the generated HTML source code :



What is the problem?


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

Siva,

I don't think you can do it .... I recall reading ... in the K&B book (I think) that you can only use scripting in classic tags ... so you can use any scripting in tag files or tags that extend SimpleTag ...

This is a great question and I'm gonna search for the exact page in the K&B book.

kf
SCJP 5.0 (preparing for SCWCD)
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
It is getting confused as the results are varying depending upon the browser we used.

See the generated HTML code they are there as template text but browser simply ignore them.
Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

Here's the reference ...

In fact, Tag File bodies are never allowed to have scripting,
so it’s not an option. But you can declare body-content (using
the tag directive with a body-content attribute) if you want one
of the other two options, empty or tagdependent.

Head First Servlets and JSP p. 508

Now .. I wonder why it is that tags that implement the 'Tag' interface can use scripting and tags that implement 'SimpleTag' cannot?
Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

The reason it shows up in the browser is that 'tagdependent' means that the container wont evaluate the body but just pass it thru to your tag (or tag file). EL, other tags and scriptlets are ignored when you use 'tagdependent'.

Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

Siva,

Found it! And it was right here on JavaRanch! Check out this post ... it explains ... why you can use scriting in classic tags (using 'JSP' in <body-content> in the TLD ) and why SimpleTags cannot (they return JspFragment which does not support scripting)


I've just noticed Im asking an answering my own questions!
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Thank you sooo much...

But still a minor doubt.

I know tag file and Simple tag body content should be empty or scriptless or tagdependent and should not be jsp.

But my question is if the bodycontent is tagdependent can they have scriptlet in their body?

So they should be displayed as template text...but since JspFragement can not contain scriptlet and has to throw translation error as per the link you posted..


if there were translation error then it would have thrown 500 internal server error right? but it is there in the html but its just the browser that did not display some of the tag....see my edited post for different behaviour of the browser for the same generated html...

So if mozilla can display the expression then that means scriptlet are passed throught the body without container evaluating it........

thanks again
Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

hmm .. I'm not sure but here's what I think is going ...

the browser (any of them) doesnt understang scriptlets or EL so its just text to the broswer. the container is not evaluating the EL expressions in the body of your tag (or any scriptlets) and is just sending them through as plain text.

The translation error would occur .. I think ... if you used 'JSP' as the value of <body-content> in the TLD of a custom tag that implemented the 'SimpleTag' interface. When the container was trying to load the taghandler, the container would know that JSP is an invalid value for the body content of a 'SimpleTag'.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Siva.

During translation time, the container sees the 'body-content', here it is 'tagdependent'. It generates the body as template text, so that the JspFragment can be able to process.

So they should be displayed as template text...but since JspFragement can not contain scriptlet and has to throw translation error as per the link you posted..


Since the container generates the body as template text, now there are nomore scriptlets. JspFragement sees this as template text and process it.
 
wood burning stoves
 
subject: <jsp:doBody> tag not displaying scriptlet as template text when the body content is tagdependent
 
Similar Threads
Error while testing attributes
The attribute directive in tag files.
JSP Scripting Elements
Displaying JSP in certain DIV tag
Need help with a servlet problem