I’ve been doing some work on the comment rendering section of Gravl, and just discovered the joy of Grails SortedSets.
I was keen to keep my comments in date order, but didn’t want the overhead of custom queries when I was enjoying just navigating the object graph (blogEntry.comments.each()
did you say?). Enter the SortedSet.
Grails lets you use SortedSets in one-to-many scenarios so you can keep things in you preferred order automatically. All I need to do was change my Comments
object to be a SortedSet in the BlogEntry class (the “one” side)…
static hasMany = [ comments : Comment, tags : Tag ] SortedSet comments
Then just needed a little work on the Comments
(the “many” side) class to implement comparable and we’re in order..
class Comment implements Comparable { ... // we keep comments sorted by date on each entry public int compareTo(Object obj) { return created <=> obj.created } }
Once that’s done, we just need to mark it up…
The custom bubbles are courtesy of Wil Mayo.
While in CSS mode, it was time to tidy up those blog entries with one of those cute CSS rolodexes. Thanks to a writeup from J Wynia it was much simpler than I thought.
Enough UI timewasting… time to actually do some work on adding new comments!