You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by ja...@apache.org on 2026/10/08 22:18:33 UTC
(grails-static-website) 01/01: Require Grails 8 fields that the GA runtime no longer implies.
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a commit to branch grails-8-required-nullability
in repository https://gitbox.apache.org/repos/asf/grails-static-website.git
commit ba6f8f345eb7ad8799db8e28d83fa16889927fcf
Author: James Fredley <ja...@users.noreply.github.com>
AuthorDate: Thu Oct 8 18:18:15 2026 -0400
Require Grails 8 fields that the GA runtime no longer implies.
Add nullable: false where blank, min, or inList no longer rejects null, and keep an optional ContactInfo submittable.
Assisted-by: opencode:grok-4.7
---
.../v8/snippets/grails-app/domain/example/Make.groovy | 2 +-
.../v8/snippets/grails-app/domain/example/Model.groovy | 3 ++-
.../snippets/grails-app/domain/example/Vehicle.groovy | 6 ++++--
.../grails-app/domain/demo/Manufacturer.groovy | 2 +-
.../v8/snippets/grails-app/domain/demo/Vehicle.groovy | 4 ++--
.../v8/guide/oneToOneWidget.adoc | 2 +-
.../snippets/grails-app/domain/example/Author.groovy | 8 ++++++++
.../v8/snippets/grails-app/domain/example/Book.groovy | 5 +++--
.../grails-app/domain/example/ContactInfo.groovy | 5 +++--
.../v8/snippets/grails-app/domain/example/Tag.groovy | 2 +-
.../grails-app/views/_fields/oneToOne/_widget.gsp | 18 ++++++++++++++++--
.../snippets/grails-app/domain/example/AuditLog.groovy | 6 +++---
12 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Make.groovy b/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Make.groovy
index e5e55fcc8c8..ff662d3ac4a 100644
--- a/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Make.groovy
+++ b/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Make.groovy
@@ -5,7 +5,7 @@ class Make {
String name
static constraints = {
- name blank: false, maxSize: 255
+ name nullable: false, blank: false, maxSize: 255
}
String toString() {
diff --git a/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Model.groovy b/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Model.groovy
index 864e6efaa7c..37ad767702c 100644
--- a/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Model.groovy
+++ b/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Model.groovy
@@ -7,7 +7,8 @@ class Model {
static belongsTo = [make: Make]
static constraints = {
- name blank: false, maxSize: 255
+ name nullable: false, blank: false, maxSize: 255
+ make nullable: false
}
String toString() {
diff --git a/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Vehicle.groovy b/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Vehicle.groovy
index d2a3acdddd8..be9a34c5ab1 100644
--- a/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Vehicle.groovy
+++ b/guides/creating-your-first-grails-app/v8/snippets/grails-app/domain/example/Vehicle.groovy
@@ -8,8 +8,10 @@ class Vehicle {
Model model
static constraints = {
- name blank: false, maxSize: 255
- year min: 1900
+ name nullable: false, blank: false, maxSize: 255
+ year nullable: false, min: 1900
+ make nullable: false
+ model nullable: false
}
// H2 treats YEAR as a reserved word; quote/rename the physical column.
diff --git a/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Manufacturer.groovy b/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Manufacturer.groovy
index 84f255c97ab..a234dce4f34 100644
--- a/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Manufacturer.groovy
+++ b/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Manufacturer.groovy
@@ -4,6 +4,6 @@ class Manufacturer {
String name
static constraints = {
- name blank: false
+ name nullable: false, blank: false
}
}
diff --git a/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Vehicle.groovy b/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Vehicle.groovy
index bcb15031215..4bf033b515c 100644
--- a/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Vehicle.groovy
+++ b/guides/database-per-tenant/v8/snippets/grails-app/domain/demo/Vehicle.groovy
@@ -11,7 +11,7 @@ class Vehicle implements MultiTenant<Vehicle> { // <1>
year column: '`year`'
}
static constraints = {
- model blank: false
- year min: 1980
+ model nullable: false, blank: false
+ year nullable: false, min: 1980
}
}
diff --git a/guides/grails-fields-custom-widgets-and-wrappers/v8/guide/oneToOneWidget.adoc b/guides/grails-fields-custom-widgets-and-wrappers/v8/guide/oneToOneWidget.adoc
index f550f27d2ab..49bb6ac52b4 100644
--- a/guides/grails-fields-custom-widgets-and-wrappers/v8/guide/oneToOneWidget.adoc
+++ b/guides/grails-fields-custom-widgets-and-wrappers/v8/guide/oneToOneWidget.adoc
@@ -14,7 +14,7 @@ include::../snippets/grails-app/views/_fields/oneToOne/_widget.gsp[]
How the dispatch works:
* `persistentProperty.bidirectional && persistentProperty.inverseSide?.owningSide` is `true` when the other side declares `belongsTo: ParentClass` (or its bidirectional equivalent). The owning side's row is created and destroyed with the parent.
-* When owned, the template uses `<f:with bean="${value ?: referencedClass.newInstance()}" prefix="${prefix}${property}.">` to recursively render `<f:all>` for the child. The `prefix` ensures the child's input names are like `author.contactInfo.phone` so Grails data binding cascades into the child object.
+* When owned, the template uses `<f:with bean="${value ?: referencedClass.newInstance()}" prefix="${prefix}${property}.">` and renders each non-association child property with `<f:field>`. The `prefix` ensures the child's input names are like `author.contactInfo.phone` so Grails data binding cascades into the child object. Grails Fields 8 ignores `required` on `<f:all>`, so an optional association passes `required="false"` to each child field. That lets the browser submit a parent with a [...]
* When not owned, the template falls through to a `<select>` of existing rows, exactly like many-to-one.
This single template handles both `Author.contactInfo` (owned, inline edit) and any future `Book.cover` style relationship (independent, select an existing image) without per-property special-casing.
diff --git a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Author.groovy b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Author.groovy
index 13fcf2ce7af..9a1ee0a499a 100644
--- a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Author.groovy
+++ b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Author.groovy
@@ -18,6 +18,14 @@ class Author {
contactInfo nullable: true
}
+ def beforeValidate() {
+ // The optional contact fieldset is always rendered. A blank submission
+ // binds a new ContactInfo, which would fail its own required fields.
+ if (contactInfo && !contactInfo.id && !contactInfo.phone && !contactInfo.mailingAddress) {
+ contactInfo = null
+ }
+ }
+
static mapping = {
sort name: 'asc'
}
diff --git a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Book.groovy b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Book.groovy
index b2f687f8ded..29d601b16cc 100644
--- a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Book.groovy
+++ b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Book.groovy
@@ -16,10 +16,11 @@ class Book {
static constraints = {
title nullable: false, blank: false, maxSize: 255
isbn nullable: false, blank: false, matches: /^(?:\d{10}|\d{13}|\d{3}-\d-\d{2}-\d{6}-\d)$/
- genre inList: ['Fiction', 'Non-Fiction', 'Biography', 'Science', 'History', 'Poetry']
+ author nullable: false
+ genre nullable: false, inList: ['Fiction', 'Non-Fiction', 'Biography', 'Science', 'History', 'Poetry']
description nullable: false, blank: false, maxSize: 2000, widget: 'textarea'
publishedDate nullable: false
- priceUSD min: 0.00G, scale: 2
+ priceUSD nullable: false, min: 0.00G, scale: 2
inStock nullable: false
}
diff --git a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/ContactInfo.groovy b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/ContactInfo.groovy
index 17052f02038..91f6c6ab929 100644
--- a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/ContactInfo.groovy
+++ b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/ContactInfo.groovy
@@ -8,8 +8,9 @@ class ContactInfo {
static belongsTo = [author: Author]
static constraints = {
- phone blank: false, maxSize: 32
- mailingAddress blank: false, maxSize: 500, widget: 'textarea'
+ author nullable: false
+ phone nullable: false, blank: false, maxSize: 32
+ mailingAddress nullable: false, blank: false, maxSize: 500, widget: 'textarea'
}
String toString() { "Contact for ${author?.name}" }
diff --git a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Tag.groovy b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Tag.groovy
index 07d5dc08f3a..3cee3e67a9e 100644
--- a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Tag.groovy
+++ b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/domain/example/Tag.groovy
@@ -8,7 +8,7 @@ class Tag {
static belongsTo = Book
static constraints = {
- name blank: false, maxSize: 60, unique: true
+ name nullable: false, blank: false, maxSize: 60, unique: true
}
static mapping = {
diff --git a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/views/_fields/oneToOne/_widget.gsp b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/views/_fields/oneToOne/_widget.gsp
index 2e41844e102..73e926db003 100644
--- a/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/views/_fields/oneToOne/_widget.gsp
+++ b/guides/grails-fields-custom-widgets-and-wrappers/v8/snippets/grails-app/views/_fields/oneToOne/_widget.gsp
@@ -14,8 +14,22 @@
<g:message code="${referencedClass.simpleName.toLowerCase()}.label"
default="${referencedClass.simpleName}"/>
</legend>
- <f:with bean="${value ?: referencedClass.newInstance()}" prefix="${prefix}${property}.">
- <f:all/>
+ <%-- Grails Fields 8 passes only bean, property, and prefix into f:all,
+ so required on f:all is ignored. Set it on each child field.
+ An optional association must not HTML-require a blank child. --%>
+ <g:set var="childBean" value="${value ?: referencedClass.newInstance()}"/>
+ <g:set var="childEntity" value="${grailsApplication.mappingContext.getPersistentEntity(referencedClass.name)}"/>
+ <f:with bean="${childBean}" prefix="${prefix}${property}.">
+ <g:each in="${childEntity.persistentProperties}" var="childProp">
+ <g:if test="${!(childProp instanceof org.grails.datastore.mapping.model.types.Association) && !(childProp.name in ['id', 'version', 'dateCreated', 'lastUpdated'])}">
+ <g:if test="${required}">
+ <f:field property="${childProp.name}"/>
+ </g:if>
+ <g:else>
+ <f:field property="${childProp.name}" required="false"/>
+ </g:else>
+ </g:if>
+ </g:each>
</f:with>
</fieldset>
</g:if>
diff --git a/guides/grails-transactional-events/v8/snippets/grails-app/domain/example/AuditLog.groovy b/guides/grails-transactional-events/v8/snippets/grails-app/domain/example/AuditLog.groovy
index a882c070296..4aef6b176d5 100644
--- a/guides/grails-transactional-events/v8/snippets/grails-app/domain/example/AuditLog.groovy
+++ b/guides/grails-transactional-events/v8/snippets/grails-app/domain/example/AuditLog.groovy
@@ -13,9 +13,9 @@ class AuditLog {
static constraints = {
eventType nullable: false, blank: false, maxSize: 64
- orderId min: 1L
- customerId min: 1L
- orderTotal min: new BigDecimal('0.01')
+ orderId nullable: false, min: 1L
+ customerId nullable: false, min: 1L
+ orderTotal nullable: false, min: new BigDecimal('0.01')
occurredAt nullable: false
}