Skip to content

Commit

Permalink
GRAILS-10986 documentation for using custom subclass of RestfulContro…
Browse files Browse the repository at this point in the history
…ller in @resource annotation
  • Loading branch information
lhotari committed May 1, 2014
1 parent f7cef38 commit 14387e5
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,38 @@ class BookController extends RestfulController {

The example above subclasses @RestfulController@ and overrides the protected @queryForResource@ method to customize the query for the resource to take into account the parent resource.

h4. Using custom subclass of RestfulController with Resource annotation

You can also customize the behaviour of the controller that backs the Resource annotation.

The class must provide a constructor that takes a domain class as it's argument. The second constructor is required for supporting Resource annotation with readOnly=true.

This is a template that can be used for subclassed RestfulController classes used in Resource annotations:
{code}
class SubclassRestfulController<T> extends RestfulController<T> {
SubclassRestfulController(Class<T> domainClass) {
this(domainClass, false)
}

SubclassRestfulController(Class<T> domainClass, boolean readOnly) {
super(domainClass, readOnly)
}
}
{code}


You can specify the super class of the controller that backs the Resource annotation with the @superClass@ attribute.

{code}
import grails.rest.*

@Resource(uri='/books', superClass=SubclassRestfulController)
class Book {

String title

static constraints = {
title blank:false
}
}
{code}

0 comments on commit 14387e5

Please sign in to comment.