Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nested tags

 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to understand how nested tags work for both classic and simple tags. This is my jsp snippet:


where Classic represents a Classic tag and Simple a Simple one.

The code snippet for the Classic tag is as follows:


The code snippet for the Simple tag is as follows:



The above snippet works fine when I try to execute.

Now when I do the reverse like :



an error is thrown which says:

/nested.jsp(14,1) jasper.error.bad.bodycontent.type
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
................................

Please let me know where I am going wrong?
[ May 13, 2008: Message edited by: Ken Sampson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

Originally posted by Ken Sampson:

<mine:Simple>
<mine:Classic />
</mine:Classic>

This syntax is not valid. You have self-closed the "classic" tag and supplied a closing tag. Do one or the other.
 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for pointing me the code formatting ... I guess this syntax is correct but i still receive the same error



I guess Classic tags cannot have Simple parents or there must be some other way to access. Please help..
[ May 14, 2008: Message edited by: Ken Sampson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your syntax is still wrong. Look at it carefully.
 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for pointing me out the error ... I guess this syntax is correct but i still receive the same error




I guess Classic tags cannot have Simple parents or there must be some other way to access. Please help..
 
John Pearson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classic tags certainly can have Simple tags as parents. Your code looks basically correct. Looking at your error message, though, my first suspicion would be that in your TLD, for Simple tag you have <body-content>empty</body-content> instead of "scriptless".
 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you John for your reply ..for your reference please find the TLD file below:



Please let me know if I am doing anything wrong
[ May 14, 2008: Message edited by: Ken Sampson ]
 
John Pearson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'm baffled. Your TLD looks good, your code looks good. I decided to try it myself, cutting and pasting your code snippets. I had to add declarations for nestedLevel and write, but I know you've got those in there or it wouldn't have compiled. When I ran it, it worked just fine! It produced the output: Tag at nestedLevel 0 1.

I guess what I would try at this point is to comment out everything in doStartTag() except the return, and see if that gets rid of the error. If it does, start adding code back in a line or two at a time.

I can't help but think that a bad.bodycontent.type error is a syntax problem in the TLD or JSP page, but I sure don't see any problems in what you've posted.
 
Prem Nazeer Mohamed Ali
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the tld file change the below

<body-content>scripless</body-content>

to

<body-content>scriptless</body-content>

it should work.
 
Musa Ali
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tested this, and obviously there is a fault in your TLD (the "scripless" instead of "scriptless") but if you look at the documentation, TagSupport and BodyTagSupport store parent as a "tag" where as SimpleTags store it as "JspTag". So if you know the class family tree, you'd know that this means that Simple tags can have any tag as it's parent (JspTag is the base class) While Tags would only allow other Tags as a SimpleTag can not be stored in a Tag variable.

At least this is what it should do theoretically
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic