Skip to content

Commit c0648ab

Browse files
committed
document enableNamespaceViewDefaults
1 parent 8c69ac2 commit c0648ab

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

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

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,4 +1162,79 @@ grails {
11621162
}
11631163
----
11641164

1165-
This allows you to use classes from these packages without explicit imports throughout your Groovy code. The `starImports` configuration works independently and will be combined with any imports from `importGrailsCommonAnnotations` or `importJavaTime` flags if those are also enabled.
1165+
This allows you to use classes from these packages without explicit imports throughout your Groovy code. The `starImports` configuration works independently and will be combined with any imports from `importGrailsCommonAnnotations` or `importJavaTime` flags if those are also enabled.
1166+
1167+
===== 12.30 Scaffolding Namespace View Defaults
1168+
1169+
Grails 7.1 introduces an opt-in feature for scaffolding that allows namespace-specific scaffolded templates to take priority over non-namespaced view fallbacks.
1170+
1171+
====== Background
1172+
1173+
Previously, when a namespace controller requested a view, the scaffolding plugin would only generate a scaffolded view if no view existed at all. This meant that if you had:
1174+
1175+
* A namespace controller (e.g., `namespace = 'admin'`)
1176+
* A non-namespaced view in `grails-app/views/event/index.gsp`
1177+
* A namespace-specific scaffolded template in `src/main/templates/scaffolding/admin/index.gsp`
1178+
1179+
The non-namespaced view would always be used, and the namespace-specific scaffolded template would be ignored.
1180+
1181+
====== New Behavior
1182+
1183+
With the new `enableNamespaceViewDefaults` configuration, namespace-specific scaffolded templates can now override non-namespaced view fallbacks. This provides better support for namespace-specific customization of scaffolded views.
1184+
1185+
====== Configuration
1186+
1187+
To enable this feature, add the following to your `application.yml`:
1188+
1189+
[source,yml]
1190+
.application.yml
1191+
----
1192+
grails:
1193+
scaffolding:
1194+
enableNamespaceViewDefaults: true
1195+
----
1196+
1197+
====== View Resolution Priority
1198+
1199+
When `enableNamespaceViewDefaults` is enabled, the view resolution priority for namespace controllers is:
1200+
1201+
1. **Namespace-specific view** (e.g., `grails-app/views/admin/event/index.gsp`)
1202+
- If exists → used (highest priority)
1203+
1204+
2. **Namespace-specific scaffolded template** (e.g., `src/main/templates/scaffolding/admin/index.gsp`)
1205+
- If exists and no namespace view → used (overrides fallback)
1206+
1207+
3. **Non-namespaced view fallback** (e.g., `grails-app/views/event/index.gsp`)
1208+
- Used if no namespace view or scaffolded template exists
1209+
1210+
4. **Non-namespaced scaffolded template** (e.g., `src/main/templates/scaffolding/index.gsp`)
1211+
- Used if no views exist at all
1212+
1213+
====== Example Use Case
1214+
1215+
This feature is useful when you want different scaffolded views for different namespaces:
1216+
1217+
[source,groovy]
1218+
----
1219+
// Regular event controller
1220+
@Scaffold(RestfulServiceController<Event>)
1221+
class EventController {
1222+
}
1223+
1224+
// Admin event controller with namespace
1225+
@Scaffold(RestfulServiceController<Event>)
1226+
class EventController {
1227+
static namespace = 'admin'
1228+
}
1229+
----
1230+
1231+
With `enableNamespaceViewDefaults: true`, you can provide:
1232+
1233+
* `src/main/templates/scaffolding/index.gsp` - Default scaffolded template
1234+
* `src/main/templates/scaffolding/admin/index.gsp` - Admin-specific scaffolded template
1235+
1236+
The admin controller will use the admin-specific template even if a non-namespaced view exists.
1237+
1238+
====== Backward Compatibility
1239+
1240+
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.

0 commit comments

Comments
 (0)