Skip to content

Commit bb6540a

Browse files
committed
update upgrade guide
1 parent 4f8387e commit bb6540a

File tree

1 file changed

+145
-1
lines changed

1 file changed

+145
-1
lines changed

grails-doc/src/en/guide/upgrading/upgrading60x.adoc

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,4 +1238,148 @@ The admin controller will use the admin-specific template even if a non-namespac
12381238

12391239
====== Backward Compatibility
12401240

1241-
This feature is **disabled by default** (`false`), ensuring complete backward compatibility. Existing applications will continue to work without any changes. Enable the feature only when you need namespace-specific scaffolded template support.
1241+
This feature is **disabled by default** (`false`), ensuring complete backward compatibility. Existing applications will continue to work without any changes. Enable the feature only when you need namespace-specific scaffolded template support.
1242+
1243+
===== 12.31 Enhanced Display Constraint with DisplayType Enum
1244+
1245+
Grails 7.1 enhances the `display` constraint with a new `DisplayType` enum that provides fine-grained control over where properties appear in scaffolded views.
1246+
1247+
====== New DisplayType Values
1248+
1249+
The `display` constraint now accepts a `DisplayType` enum value in addition to boolean values:
1250+
1251+
|===
1252+
|Value|Description
1253+
1254+
|`ALL`|Display in all views. Overrides the default blacklist for properties like `dateCreated` and `lastUpdated`.
1255+
|`NONE`|Never display in any view. Equivalent to `display: false`.
1256+
|`INPUT_ONLY`|Display only in input views (create and edit forms).
1257+
|`OUTPUT_ONLY`|Display only in output views (show and index/list views).
1258+
|===
1259+
1260+
====== Example Usage
1261+
1262+
[source,groovy]
1263+
----
1264+
import static grails.gorm.validation.DisplayType.*
1265+
1266+
class Book {
1267+
String title
1268+
String isbn
1269+
Date dateCreated
1270+
Date lastUpdated
1271+
String internalNotes
1272+
1273+
static constraints = {
1274+
dateCreated display: ALL // Override blacklist, show in all views
1275+
lastUpdated display: OUTPUT_ONLY // Show only in show/index views
1276+
isbn display: INPUT_ONLY // Show only in create/edit forms
1277+
internalNotes display: NONE // Never show
1278+
}
1279+
}
1280+
----
1281+
1282+
====== Backward Compatibility
1283+
1284+
Boolean values continue to work as before:
1285+
1286+
* `display: true` - Default behavior (property is displayed)
1287+
* `display: false` - Equivalent to `DisplayType.NONE`
1288+
1289+
No changes are required for existing applications using boolean values.
1290+
1291+
===== 12.32 @Scaffold Annotation (Preferred Approach)
1292+
1293+
Starting in Grails 7.1, the `@Scaffold` annotation is the preferred approach for enabling scaffolding on controllers and services. While the legacy `static scaffold = Domain` syntax is still supported, the annotation provides additional features and flexibility.
1294+
1295+
====== Benefits of @Scaffold
1296+
1297+
* **Supports both controllers and services** - The annotation works on both artefact types
1298+
* **Custom class extension** - Specify a custom class to extend using the generic syntax
1299+
* **Service-backed controllers** - Create controllers that delegate to a service layer for better separation of concerns
1300+
* **Read-only mode** - Built-in support for read-only scaffolding
1301+
1302+
====== Migration Examples
1303+
1304+
**Basic controller scaffolding:**
1305+
1306+
[source,groovy]
1307+
----
1308+
// Legacy syntax
1309+
class BookController {
1310+
static scaffold = Book
1311+
}
1312+
1313+
// New preferred syntax
1314+
import grails.plugin.scaffolding.annotation.Scaffold
1315+
1316+
@Scaffold(Book)
1317+
class BookController {
1318+
}
1319+
----
1320+
1321+
**Scaffolded service:**
1322+
1323+
[source,groovy]
1324+
----
1325+
import grails.plugin.scaffolding.annotation.Scaffold
1326+
1327+
@Scaffold(Book)
1328+
class BookService {
1329+
}
1330+
----
1331+
1332+
**Service-backed controller (delegates to BookService):**
1333+
1334+
[source,groovy]
1335+
----
1336+
import grails.plugin.scaffolding.annotation.Scaffold
1337+
import grails.plugin.scaffolding.RestfulServiceController
1338+
1339+
@Scaffold(RestfulServiceController<Book>)
1340+
class BookController {
1341+
}
1342+
----
1343+
1344+
**Custom class to extend:**
1345+
1346+
[source,groovy]
1347+
----
1348+
import grails.plugin.scaffolding.annotation.Scaffold
1349+
import com.example.MyCustomService
1350+
1351+
@Scaffold(MyCustomService<Book>)
1352+
class BookService {
1353+
}
1354+
----
1355+
1356+
**Read-only scaffolding:**
1357+
1358+
[source,groovy]
1359+
----
1360+
import grails.plugin.scaffolding.annotation.Scaffold
1361+
1362+
@Scaffold(domain = Book, readOnly = true)
1363+
class BookController {
1364+
}
1365+
----
1366+
1367+
====== CLI Commands
1368+
1369+
New CLI commands are available to generate scaffolded controllers and services:
1370+
1371+
[source,bash]
1372+
----
1373+
# Generate a scaffolded controller
1374+
grails create-scaffold-controller Book
1375+
1376+
# Generate a scaffolded service
1377+
grails create-scaffold-service Book
1378+
1379+
# Generate both service and controller
1380+
grails generate-scaffold-all Book
1381+
----
1382+
1383+
These commands support options like `--extends` to specify a custom class to extend, `--namespace` for controller namespacing, and `--service` to use `RestfulServiceController`.
1384+
1385+
For full details, see the link:{guidePath}scaffolding.html[Scaffolding] documentation.

0 commit comments

Comments
 (0)