Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<body-content> specification of a tag in TLD

 
Suhas Wadadekar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I learnt that the <body-content> specification of a tag in the TLD can have one of following four possible values: empty, scriptless, tagdependant, JSP

But when we create a custom tags why can we not include script in the tag body, when JSP could be a possible value of tag's <body-content>?

Thanks,
Suhas.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2535
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you writing a simple tag? For simple tags the value JSP is not allowed.

Regards,
Frits
 
Suhas Wadadekar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly.

This is what I was doing:



Why is this wrong when I have scriptlet inside a Classic Tag, that happens to be under Simple Tag?

Thanks,
Suhas.
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create a custom tag, your Java class must implement one of two interfaces. Tag or SimpleTag. Classes that implement the Tag interface are called 'classic' tags. Classes that implement SimpleTag are called 'simple' tags.

Only 'classic' tags can have 'JSP' as body content. Simple tags can never have scripting (like in your example) in their body content.

By the way ... scripting in JSPs is considered to be very very bad coding practice! Ideally there should be no scripting in your pages. Also, TagSupport and SimpleTagSupport are convenience classes you should extend to make your custom tags.
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another point ...

In the spec ... it explains that 'cooperating tags' (tags nested inside one another) that are classic tags can have only classic tag parents .. simple tags can have either classic tag parents or simple tag parents. There is an adapter you can use as a work-around. but thats why its 'wrong'.
 
Suhas Wadadekar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only 'classic' tags can have 'JSP' as body content. Simple tags can never have scripting (like in your example) in their body content.


In my example, isnt the script inside a classic tag?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2535
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to do some coding to get it working. Can you post your code?
Frits
 
Suhas Wadadekar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have code. I am just trying to figure out that if a Simple Tag contains a Classic Tag, and if the inner Classic Tag contains scripting code, does that imply the outer Simple Tag contains scripting code?
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suhas,

No ... it does not ... each tag has its own body. Classic tags can have scripting if the body content type is 'JSP' and Simple tags can never have scripting.

But you should try it!!! ... write a small classic tag and a simple tag and give it a try!!

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2535
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When testing with tomcat 5.5 it shows that it doesn't allow it:
The jsp

The TLD entries


and the InnerBodyTagSupport:

The OuterSimpleTagSupport:


And the Container comes with the following error:

It seems that tomcat doesn't allow it according to the TLD, which makes sense, because like Keith was saying: SimpleTags where introduced to remove the scriptlets in the JSPs
 
Suhas Wadadekar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith, Frits.

I did try out the Classic and Simple tags individually. Simple tags have a problem with scripting while Classic tags dont.

Now as I have been trying to figure out, I put scripting code in a Classic tag and put that Classic Tag inside a Simple Tag. To this the container (Tomcat 6.0.20) complained, like Frits had pointed out:
Scripting elements ( <%!, <jsp:declaration, <%=, <jsp:expression, <%, <jsp:scriptlet ) are disallowed here.


So for now, I am assuming:
If there is scripting code in a Simple Tag, whether directly in it's body or not, it is not allowed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic