• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tutorial on creating custom tags  RSS feed

 
Andrew Black
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a tutorial on creating my own custom tags. My attemps to google have led me to some rather old pages that I suspect are for an older API.

A specific question. What are the pros and cons of implementing your tags with Java code as opposed to .tag files? My suspicion is the latter is quicker and easier but are there gotchas in the longer term.

Using Tomcat 5.0
[ January 31, 2006: Message edited by: Andrew Black ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Andrew. I know of no up-to-date tutorials such as you seek, but with regards to your other question: tag files and Java-based handlers are simply different tools, each of which is the most appropriate choice for particular types of tasks. I make use of both types of handlers extensively, choosing whichever is more appropriate for the tag to be implemented.

If the tag is primarly intended to spit out HTML markup or is suited to a JSP implementation, the use of tag files is indicated. Otherwise, a Java-based tag handler is what I will use.

One is "better" than the other only in relation to the job that needs accomplishing
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The relationship between custom tags in java code as opposed to .tag files is pretty much the same as the relationship between servlets and JSP. If you understand that one, this one becomes a lot easier.
A JSP gets parsed, translated into java code (class that implements javax.servlet.Servlet) compiled and run.
A .tag file gets parsed, translated into java code (class that implements javax.servlet.jsp.tagext.SimpleTag) compiled and run.

With respect to learning tags, I would say go through the old tutorials anyway, and learn the java coding approach. Things haven't changed that much. The concepts are the same, and understanding the concepts of the java coding approach IMO will then make writing .tag files eaiser.

The other recommendation I would make is to look at existing taglibraries. Particularly the JSTL, and also maybe the Struts tags.
See how they design their tags consistently, how they pass in attributes/values etc etc.

Cheers,
evnafets
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!