Monday, August 27, 2012

The not so obvious fact about tag libraries

I've came across this thing today and quite frankly I feel a little bit ashamed that I didn't know it yet. The concept of tag libraries is not new in the JSP world. It's just unusual to write tags because one needs to provide a tag library description file along with it and that increases the complexity of the solution (or so it is seen).

The nice thing about tag libraries is that they don't necessarily need a TLD file to drive them - a folder is more than enough for simple cases:

File /WEB-INF/tags/hello.tag
Hello, world! from a tag
File /index.jsp
<@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

<tags:hello />
It's really that simple!

There's obviously more to it (how to pass the tag body, how to pass parameters to the tag) - maybe next time :)

No comments: