• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

taglib-directive tagdir and uri

 
Salah Lejmi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About tag files, you forgot : in the /WEB-INF/tags/ directory (or a subdirectory of /WEB-INF/tags/) of the web application.
 
Salah Lejmi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic