GeeCON Prague 2014*
The moose likes Servlets and the fly likes What are tag libs? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "What are tag libs?" Watch "What are tag libs?" New topic
Author

What are tag libs?

Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
This may look like a sally question, but I really don't have an idea about how do they work, anf how do I use them.
Can anyone give me an example of a reusable tag, and a tag lib?
Are those related to java packages?, or java beans?
Thanks.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Chk out these tutorials. for details.
Basically Tag Libs are a way to develop your own tags like the
ones you use in HTML ex: H1, H2 etc for headings etc.
Not direclty related to packages or beans, but they can be developed using bean concepts.
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Joe McGuire
Ranch Hand

Joined: Mar 19, 2001
Posts: 293
JSP tag libraries are a collection of custom built tags which produce an XML-based script (custom actions presented as tags). The logic component is separated in a JavaBean.
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
And may this tags have behavior or are they only for format purposes.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
yes, they could have behavior, like in a table,
repeating a certain steps in a for loop etc.
Is this what you are asking when you say "behavior"?
Not sure I understand you correctly.
regds.
- satya
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
JSP Tags have whatever behavior you program into them. There are tags that allow logging to occur from your JSP page so you can track thing. The Jakarta full Tag Lib has session tags, request and response tags, log tags, db tags etc.
------------------
Hope This Helps
Carl Trusiak, SCJP2


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
Thanks Madhav, Joe, Carl.

Prasad Subramanian
Greenhorn

Joined: Aug 24, 2000
Posts: 4
Taglibs are a collection of Java Classes that follow the Java Beans model ,and implement a particular function ( like iterating thru a collection or a recordset).These functions are accesible in JSP using custom tags.
Custom tags are similar to ordinary tags in HTML like <HTML>/<HTML> , <BODY>/<BODY>.
You can specify your own name for these with a set of attributes foe each tag. Each tag would have a TagHandler class ( the Java Class I mentioned above), that would implement a Tag Interface or
derivative of it (javax.servlet.jap.tagext.*). The TagHandler would need to have a setter method for each of the attributes.
The Tag Handler would implement the exact function of the Tag and a TagLibraryDescriptor (which is a XML file) would create a mapping between the tag handler class and the tag name.
It would also contain additional details on the attributes, their types,variable defined by the tag if any ,and auxiallary calsses to validate the tags.
eg:
<foo:customtag attri1="val1" attr2="val2">
//Body of the tag
</foo:customtag>

Prasad
manav kher
Ranch Hand

Joined: Nov 21, 2000
Posts: 98
yep and the best part about defining your own tags is
1. you have no trouble implementing OLAF (one look and feel in your application or across multiple applications)
2. Changes/modifications have to be made in one place and not in individual jsp's
3. You are following sun's new pattern Model-View-Control to the t (or is it z...)
and i really want this book :-)
-manav
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
I don't understand why do we need to specify the prefix attribute in the taglib directive though. I think specifying the uri attribute should be enough to let the JSP container to look for the tag because the tag tld already linked the uri "name" to the "tag".
Adam Chace
Greenhorn

Joined: May 24, 2001
Posts: 14
The prefix is especially useful when you are using more than one library of tags in a particular JSP to prevent name conflicts.


Adam Chace<BR>Author of :<A HREF="http://www.amazon.com/exec/obidos/ASIN/193011009X/electricporkchop/102-2552103-3190518" TARGET=_blank rel="nofollow">JSP Tag Libraries</A><BR><A HREF="http://www.chalkcreek.com" TARGET=_blank rel="nofollow">Chalk Creek Software</A>
 
GeeCON Prague 2014
 
subject: What are tag libs?