RDFa Plugin

  • Tags : rdf, rdfa
  • Latest : 0.1.1
  • Last Updated: 04 October 2009
  • Grails version : 1.1.1 > *
  • Authors : null
1 vote
Dependency :
compile ":rdfa:0.1.1"




grails install-plugin rdfa


RDFa Plug-in

The RDFa plug-in allows you to expose relevant parts of the structure of your application as RDFa annotations in your views. Both domain model (non-information resources) and controller actions (information resources) can be described.


To install the RDFa plug-in just run the following command

grails install-plugin rdfa


The RDFa plug-in provides a RDFaTagLib that can be used in any of your Grails views. To achieve this, the plug-in processes Groovy-to-RDF mappings in the domain model and in controllers.

Model mapping

An example of how to expose the domain model as RDFa can be seen below.

class Person {
	static rdf = [

String name static hasMany = [friends:Person] }

The mapped fields can now be referenced in views. Add a DOCTYPE declaration

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">

and start using rdfa tags.

<rdfa:ul about="${person}">
	<g:each var="friend" in="${person.friends}">
		<rdfa:li rel="friends" resource="${friend}" property="name" />

Finally, the following XHTML+RDFa will be rendered:

<ul about="http://example.com/person/resource/1" typeof="ns1:Person" xmlns:ns1="http://xmlns.com/foaf/0.1/">
	<li rel="ns1:knows" resource="http://example.com/person/resource/2" property="ns1:name">
		John Doe II
	<li rel="ns1:knows" resource="http://example.com/person/resource/3" property="ns1:name">
		John Doe III

Controller mapping

It is important to distinguish between the thing you're describing (the domain model object), and its description (the view rendered by a controller action). E.g., a Person in a domain model can have a name, whereas a document describing this person cannot, but can have other information such as creation date or terms of use. Hence, the controller needs an additional action for identifying domain objects, and the relation of controller actions to the domain model objects need to be specified.

class PersonController {
	static rdf = [
		resource: { it.id },	// name of identifying action and identity field of domain model object

def show = { [person:Person.get(params.id)] }

def resource = { redirect(action:show,id:params.id) }

def image = { redirect(uri:"/images/default-avatar.png") } }

The mapped actions can now be referenced in views.

<rdfa:p about="${person}">
	<rdfa:img rel="image" alt="depiction of ${person.name}" />

The following XHTML+RDFa will be rendered:

<p about="http://example.com/person/resource/1" typeof="ns1:Person" xmlns:ns1="http://xmlns.com/foaf/0.1/">
	<img rel="ns1:depiction" src="http://example.com/person/image/1" alt="depiction of John Doe I" >

Consuming Linked Data

You can also expose RDFa of other objects than just mapped domain model objects. Using the enclosed object triple mapping implementation, you can add resources from other datasets as well and reference them in views.

GraphService graphService
def berlin = graphService.get("http://dbpedia.org/resource/Berlin", vocab.dbpedia.City)


  • beautiful XML namespace declarations (e.g., "foaf" instead of "ns1")
  • automatically guess, e.g., rel="friends" from <g:each in="${person.friends}">...</g:each>
  • Make better use of existing URLMapping (do not require ID closure in controller)