Display Message Threads with a Custom Tag

Now we need to add nesting to our message list in order to visualize the various threads in our forum. We’ll do this with a custom GSP tag. If you’ve ever written custom JSP tags or JSF components, come out from under the table. It’s not like that at all. But just to reassure you, before we get started on our custom tag, we’ll take a brief look at what it takes (or more important perhaps, doesn’t take) to create a GSP tag.

A Brief Introduction to GSP Tags

The first step is to create a TagLib. A TagLib is a Groovy class with a name ending in (surprise, surprise!) TagLib, and it lives in the grails-app/taglib directory. Grails provides a convenience script to create this for us:

 
$ ​grails create-tag-lib ...

Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.