diff --git a/src/en/guide/scaffolding.gdoc b/src/en/guide/scaffolding.gdoc index 65cbccefed5..4574414c55a 100644 --- a/src/en/guide/scaffolding.gdoc +++ b/src/en/guide/scaffolding.gdoc @@ -3,98 +3,20 @@ Scaffolding lets you generate some basic CRUD interfaces for a domain class, inc * The necessary [views|guide:gsp] * Controller actions for create/read/update/delete (CRUD) operations -As of Grails 2.3, the scaffolding feature has been moved to a plugin. By default this is configured for installation in new applications, but if you are upgrading from a previous version of Grails you will need to add the following configuration to your @BuildConfig.groovy@ file: +The way for an application to express a dependency on the scaffolding plugin is by including the following in @build.gradle@. {code} - plugins { - ... - compile "\:scaffolding:2.0.0" - ... - } -{code} - -Version 1.0.0 of the plugin provides the same scaffolding seen in Grails 2.2.x and below. Version 2.0.x of the scaffolding plugin includes different scaffolding templates that are aligned with the new REST APIs introduced in Grails 2.3 and above. - -h4. Dynamic Scaffolding - -The simplest way to get started with scaffolding is to enable it with the @scaffold@ property. Set the @scaffold@ property in the controller to @true@ for the @Book@ domain class: - -{code:java} -class BookController { - static scaffold = true -} -{code} - -This works because the @BookController@ follows the same naming convention as the @Book@ domain class. To scaffold a specific domain class we could reference the class directly in the scaffold property: - -{code:java} -class SomeController { - static scaffold = Author -} -{code} - -With this configured, when you start your application the actions and views will be auto-generated at runtime. The following actions are dynamically implemented by default by the runtime scaffolding mechanism: - -* index -* show -* edit -* delete -* create -* save -* update - -A CRUD interface will also be generated. To access this open @http://localhost:8080/app/book@ in a browser. + dependencies { -If you prefer to keep your domain model in Java and [mapped with Hibernate|guide:hibernate] you can still use scaffolding, simply import the domain class and set its name as the @scaffold@ argument. + // ... -You can add new actions to a scaffolded controller, for example: + runtime "org.grails.plugins:scaffolding" -{code:java} -class BookController { - - static scaffold = Book - - def changeAuthor() { - def b = Book.get(params.id) - b.author = Author.get(params["author.id"]) - b.save() + // ... - // redirect to a scaffolded action - redirect(action:show) } -} {code} -You can also override the scaffolded actions: - -{code:java} -class BookController { - - static scaffold = Book - - // overrides scaffolded action to return both authors and books - def index() { - [bookInstanceList: Book.list(), - bookInstanceTotal: Book.count(), - authorInstanceList: Author.list()] - } - - def show() { - def book = Book.get(params.id) - log.error(book) - [bookInstance : book] - } -} -{code} - -All of this is what is known as "dynamic scaffolding" where the CRUD interface is generated dynamically at runtime. - -{note} -By default, the size of text areas in scaffolded views is defined in the CSS, so adding 'rows' and 'cols' attributes will have no effect. - -Also, the standard scaffold views expect model variables of the form @InstanceList@ for collections and @Instance@ for single instances. It's tempting to use properties like 'books' and 'book', but those won't work. -{note} - h4. Customizing the Generated Views The views adapt to [Validation constraints|guide:constraints]. For example you can change the order that fields appear in the views simply by re-ordering the constraints in the builder: