• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

called tag file with scripting inside

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi guys, todays achievement

Called a tag file with scriptlets inside

Here is the code of tag and jsp . Please tell me how did I make the miracle happen?

useTag.jsp


mytag.tag


Output:


I have always been told that tag file and simple tags cannot have scriptlets inside. But is it allowed to have scriptlets when the body-content is tagdependent?
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

have always been told that tag file and simple tags cannot have scriptlets inside.


Well, you can, but you shouldn't use them as Tag files were created to remove them.....

JSP.8 Tag files bring the power of reuse to the basic page author, who are not required to know
Java.



Even in the specs you can see that it is possible:

JSP.8.8 Implicit Objects
Tag library developers writing tag files have access to certain implicit objects
that are always available for use within scriptlets and expressions through
scripting variables that are declared implicitly at the beginning of the tag handler
implementation. All scripting languages are required to provide access to these
objects .......


It is good that you tried it, but quickly forget about it

Regards,
Frits
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok.. so you mean I can have scriptlets inside the tag files and simple tags when their body-content is declared as tagdependent. But there is no point having scriplets inside because they are just flushed as html when we invoke <jsp:doBody>

They are neither executed in calling JSP nor are in called tag files right?

JSP.8.8 Implicit Objects
Tag library developers writing tag files have access to certain implicit objects
that are always available for use within scriptlets and expressions through
scripting variables that are declared implicitly at the beginning of the tag handler
implementation. All scripting languages are required to provide access to these
objects .......


This line I don't feel implies that you can have scriplets inside a call to a tag file , it is just saying that tag files within themselves can have scripting and have access to scripting variables.
It is like doing this-

mytag.tag


Have you seen any line in specs which says if you have a bodycontent as tagdependent then we can have scripting inside call to tag files and call to simple tags?
I just wanted to confirm that this behaviour is not container specific .
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Have you seen any line in specs which says if you have a bodycontent as tagdependent then we can have scripting inside call to tag files and call to simple tags?


No, but tagdependent just means that the taghandler should handle the body (whatever is written in it).
You are right they (scriptlets inside the body) are completely ignored when you try to invoke/execute them. As far as I remember the specs do not say what should be done in such a case. So the outcome is a bit container specific.

Actually what I was saying with

Tag library developers writing tag files have access to certain implicit objects
that are always available for use within scriptlets and expressions through
scripting variables that are declared implicitly at the beginning of the tag handler


was, that you can have scriptlets inside the Tag file:

Output:

Hello Frits!!

1282465592609


I have no idea why they didn't restrict that possibility. (in the specs I mean)

Regards,
Frits
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm... there shall be no need of scripting in tag file.. but its still there.

So the outcome is a bit container specific.



Can someone try the code I presented in the first post in websphere or something?
May be that will give us a clear idea.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Parth!

I tried your code on Jboss and it gives an error 500:

org.apache.jasper.JasperException: /jsp/index.jsp(19,27) Scripting elements ( <%!, <jsp:declaration, <%=, <jsp:expression, <%, <jsp:scriptlet ) are disallowed here.



I think we proved the container specific behaviour!

Regards,
Frits
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there we get it, ya right..

I think for the exam I shall assume that scripting is not allowed in tag files and simple tags even if their bodycontent is declared to be tagdependent or will mark that its container specific( if there is some vendor specific kind of option ).

Right?
reply
    Bookmark Topic Watch Topic
  • New Topic