• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What are tag libs?

 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Joe McGuire
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And may this tags have behavior or are they only for format purposes.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Madhav, Joe, Carl.

 
Prasad Subramanian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
manav kher
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The prefix is especially useful when you are using more than one library of tags in a particular JSP to prevent name conflicts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic