Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes taglib-directive tagdir and uri Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "taglib-directive tagdir and uri" Watch "taglib-directive tagdir and uri" New topic
Author

taglib-directive tagdir and uri

Salah Lejmi
Greenhorn

Joined: Jul 25, 2008
Posts: 22
Hello there !

For my preparation for SCWCD 5.0 i was a little bit confused about the taglib directive. I tested a little bit and this is the result of what i understood: (maybe you can correct me if i am wrong)

- first of all the syntax:

    <%@taglib prefix="somePrefix" uri="someURI" %> OR
    <%@taglib prefix="somePrefix" tagdir="/WEB-INF/tags[/someDir]*" %>

- Now to the use cases:


1. uri="someURI": someURI is any text the container will look for in following:

-1a: web.xml in <taglib>-tag

  <taglib>
    <taglib-uri>someURI</taglib-uri>
    <taglib-location>/WEB-INF/anyDir/mytags.tld</taglib-location>
  </taglib>

in this case an <uri>-tag is NOT needed in the tld-file.


-1b: *.tld located in /WEB-INF or sudir of /WEB-INF OR in jar-file/META-INF or subdir of jar-file/META-INF
where jar-file is any *.jar in the /WEB-INF/lib directory

These tld files must have an <uri>-tag with "someURI" in it.
    <uri>someURI</uri>

THIS can be used for all tag handlers: Classic Tag Handler, Simple Tag Handler or tag files

- In the case of "tag files *.tag" in a .jar-file in /WEB-INF/lib:
The tag files *.tag must reside in jar-file/META-INF/tags or subdir of it and
a tld file must exist in jar-file/META-INF or subdir of it with <uri>someURI</uri> tag in it .



2. tagdir="/WEB-INF/tags[/someDir]*"

this attribute is only used with tag files "*.tag" in the /WEB-INF/tags or subdir (in the root of the web application).

In this case the tag files do not need any tld-file.
the declaration of the attributes and others are in tag file itself.
<%@tag .... %>
<%@attribute ... %>

I hope i could help.
[ October 19, 2008: Message edited by: Salah Lejmi ]

SCJP 5.0 (95%), SCWCD 5.0 (98%)<br />Salah Lejmi
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

About tag files, you forgot : in the /WEB-INF/tags/ directory (or a subdirectory of /WEB-INF/tags/) of the web application.


[My Blog]
All roads lead to JavaRanch
Salah Lejmi
Greenhorn

Joined: Jul 25, 2008
Posts: 22
Originally posted by Christophe Verre:
About tag files, you forgot : in the /WEB-INF/tags/ directory (or a subdirectory of /WEB-INF/tags/) of the web application.


that's right.
thank you.
Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 165

1c: What about when we don't specify mapping in web.xml and no uri in tld either.
In that case the container will attempt to use the uri attribute in the <%@ taglib directive as a path to the actual tld.

In simple and classic tags we need tld for specifying things like <body-conent>, <attribute> and <variable> AND to get to the tag handler class.
So uri in <%@ taglib directive is used to reach to the tld.
But when using tag files we specify things like <body-content>,<attribute> and <variable> in tagfile itself but we need to get to the tagfile somehow.

When tagfile is inside /WEB-INF/lib/jar/META-INF/tags (or subdir) we use tld in...jar/META-INF (or subdir) and specify uri in<%@tagdir attribute. which leads us to the tld which leads us to tagfile.( Can we use tagdir attribute in this case which directly leads us to tagfile ) [u]

And why do we use tagdir for tagfiles outside jar?
Was using uri attribute not enough?( we can always make a tld ). Is it just for covenience or any other reason?




Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Bindu.
And why do we use tagdir for tagfiles outside jar?
Was using uri attribute not enough?( we can always make a tld ). Is it just for covenience or any other reason?


If we use 'uri' attribute in 'taglib directive', we have to write the following code in the corresponding tld file I think inorder to avoid that 'tagdir' is introduced. By using it we can simply declare tagdir="/WEB-INF/tags" attribute in taglib directive inorder to access tagfile.
Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 165

If we use 'uri' attribute in 'taglib directive', we have to write the following code in the corresponding tld


yes.Thats what we do when tagfile is in jar.
Bindu Lakhanpal
Ranch Hand

Joined: Oct 17, 2008
Posts: 165

Using tagdir to access tagfile directly seems good and convenient but does it not reduce flexibility just in case we want to change the name of tagfile or its location? Then we would have to make the change in all the jsps using that tagfile.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Bindu. If we want to change the location, we have to put it under /WEB-INF/tags or any sub directory of it(if presents in jar, it must be under /META-INF/tags or any sub directory of it). The container will search for that. If we change the name of the tagfile, we have to make change in the jsp.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: taglib-directive tagdir and uri
 
Similar Threads
What will the "tagdir" attribute be for a tag file inside /META-INF/tags of a jar?
Tag file deployed in a JAR?
missing struts*.tld files
Taglib and Tagdir question?
Tag Files : why TLD requires