This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to define a local TLD in web.xml?  RSS feed

 
Achchan Chaghi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have said that instead of repeating e.g.:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
in all of your jsp pages you could do this once in web.xml and also instead of a remote uri can save a version of TLD locally and point to it.

Now I have some questions:

1. Could you please tell me what tag should I use in web.xml and how to set this relative path by an example?

2. When I use for example: uri="http://java.sun.com/jsf/core" does it really go to this remote site and checks it or some cache mechanism is used by my servlet container?

3. I extracted TLDs from my jar files in lib directory. Did not tomcat do this itself for me?

-Thanks in advance for your time and help
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Could you please tell me what tag should I use in web.xml and how to set this relative path by an example?

Look for <jsp-config> and its subtag <taglib>. But you shouldn't need this as your container has ways to detect uris.

2. When I use for example: uri="http://java.sun.com/jsf/core" does it really go to this remote site and checks it or some cache mechanism is used by my servlet container?

No, it's just a keyword used to identify the library.

3. I extracted TLDs from my jar files in lib directory. Did not tomcat do this itself for me?

You don't need to extract the tlds. They should be under META-INF in the JAR file, and will be read properly by your container.

(I'm assuming that you are using a Servlet 2.4 compliant container. Don't know about 2.3)
 
Achchan Chaghi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Satou,
Your help was really saved my time!
-Best wishes
 
Achchan Chaghi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I entered below section in my web.xml because of not repeating
<%@ taglib=blaBla in each jsf page:

<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsf/core</taglib-uri>
<tablig-location>/tld/myfaces_core.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsf/html</taglib-uri>
<tablig-location>/tld/myfaces_html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://myfaces.apache.org/tomahawk</taglib-uri>
<tablig-location>/tld/tomahawk.tld</taglib-location>
</taglib>
</jsp-config>

It seems that it does not work for me. Is there another way to achieve my goal?
PS: I am using eclipse wtp and my directory schema is such as: MyApp/WebContent/WEB-INF/tld and all tld files are in this tld folder.

-Thanks in advance
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, I did not read your first question properly
You will have to define the prefix to use for each library in the JSP pages.
You can put everything :
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
in one JSP file (say include.jsp), and include that file in all your pages.

If you don't want to include it in all pages, you can set it in web.xml using the <include-prelude> tag.

You don't need to extract the TLD files. Just put the JARs in the lib directory.
[ August 09, 2006: Message edited by: Satou kurinosuke ]
 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find my answers in bold

Hi,
I have said that instead of repeating e.g.:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
in all of your jsp pages you could do this once in web.xml

What you said above is absolutely not possible. Of course, you can specify <taglib-uri> and <tablig-location> using <taglib> in web.xml. This is done just to inform the container about the location of tld file and the logical name bound to it which we may use in taglib directive of our JSPs. But all that configuration in web.xml is not required in webservers compliant with JSP2.0 specification. Because these servers will automatically create map of tlds and their URIs if we just put them under lib/tlds directory. Whenever you would want to use TAGS, you will have to use the taglib directive and specify the uri and prefix in it. Once this is done, you can use the tags contained in that tld using the prefix that you specifed in the taglib directive


and also instead of a remote uri can save a version of TLD locally and point to it.

URI is just a name we give to the tld. Thats it. This is not like referring or downloading that tlds from a remote location.

[ August 09, 2006: Message edited by: Kalyana Sundaram ]
[ August 09, 2006: Message edited by: Bear Bibeault ]
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kalyana, I recommend you take another read of Satou's post, and then look at the JSP2.0 specification Sections JSP.1.10.4, and JSP.3.3.5.

What Satou has described using a <include-prelude> tag in web.xml is perfectly valid.
This only works in JSP2.0 containers (was defined with JSP2.0)



This is like putting a global <%@include %> at the top of every JSP in the webapp. If you put your taglib declarations into this "prelude" it will import them onto every page.

However I don't think I will be doing this, as Eclipse isn't smart enough to know about the implicit include, and is complaining with warnings about unknown tags.
For now, pasting this onto the top of every JSP page is still going to be standard for me.

Thanks Satou. I learned something today.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kalyana Sundaram:
Please find my answers in bold


I have removed the bolding from the post.

Please do not post in all bold. Use bold and other special renditions sparingly in order to express emphasis.
[ August 09, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use the prelude quite successfully for this very purpose.

I like to keep as much clutter off the page as possible.
 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer Satou And Stefan, Thanks a lot for your indication

This is really a useful tip for me!!!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!