Last updated by 5 years ago

Page: Commentable Plugin, Version:1

Commentable Plugin

This plugin provides a generic way to add and manage comments for a given application

Requirements

  • Grails Version: 1.1 and above
  • JDK: 1.5 and above

Installation

grails install-plugin commentable

Usage

Implement the Commentable interface:

import org.grails.comments.*

class Vehicle implements Commentable { }

Add some comments:

def user = User.get(1)
def v = Vehicle.get(1)

v.addComment(user, "I prefer red cars") .addComment(user, "I prefer sporty cars")

Query:

def v = Vehicle.get(1)
v.comments.each { println it.body }

In a GSP:

<comments:each bean="${vehicle}">
     ${comment.body} - Posted by ${comment.poster}
</comments:each>

The plugin also features a generic plugin component. To use you may need to define a poster evaluator in grails-app/conf/Config.groovy. The default one looks like:

grails.commentable.poster.evaluator = { request.user }

But if you store users in the session instead you may want this to be:

grails.commentable.poster.evaluator = { session.user }

You can then use the <comments:render> tag to render all comments with a comment editor:

<comments:render bean="${vehicle}" />