Skip to content

Commit bdecfc0

Browse files
committed
Make grace-plugin-fields and grace-plugin-scaffolding works
- Add grace-scaffolding-core grace-plugin-fields grace-plugin-scaffolding submodules - Update Gradle build script - Add `grails-plugin.xml` for grace-plugin-fields and grace-plugin-scaffolding - Add `@TagLib` to `FormFieldsTagLib` - Update `ContextMarkupRenderer` `ContextMarkupRendererImpl` `DomainMarkupRendererImpl` `DelegatingBeanPropertyAccessorImpl` - Update `DomainMarkupRendererSpec` and `FormFieldsTemplateServiceSpec` See gh-1211 See gh-1212
1 parent a084193 commit bdecfc0

File tree

25 files changed

+305
-199
lines changed

25 files changed

+305
-199
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ol class="property-list ${domainClass.decapitalizedName}">
2+
<g:each in="${domainProperties}" var="p">
3+
<li class="fieldcontain">
4+
<span id="${p.name}-label" class="property-label"><g:message code="${domainClass.decapitalizedName}.${p.name}.label" default="${p.defaultLabel}" /></span>
5+
<div class="property-value" aria-labelledby="${p.name}-label">${body(p)}</div>
6+
</li>
7+
</g:each>
8+
</ol>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<table>
2+
<thead>
3+
<tr>
4+
<g:each in="${domainProperties}" var="p" status="i">
5+
<g:sortableColumn property="${p.property}" title="${p.label}" />
6+
</g:each>
7+
</tr>
8+
</thead>
9+
<tbody>
10+
<g:each in="${collection}" var="bean" status="i">
11+
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
12+
<g:each in="${domainProperties}" var="p" status="j">
13+
<g:if test="${j==0}">
14+
<td><g:link method="GET" resource="${bean}"><f:display bean="${bean}" property="${p.property}" displayStyle="${displayStyle?:'table'}" theme="${theme}"/></g:link></td>
15+
</g:if>
16+
<g:else>
17+
<td><f:display bean="${bean}" property="${p.property}" displayStyle="${displayStyle?:'table'}" theme="${theme}"/></td>
18+
</g:else>
19+
</g:each>
20+
</tr>
21+
</g:each>
22+
</tbody>
23+
</table>

grace-plugin-fields/build.gradle

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
dependencies {
2-
api "org.graceframework:grace-web-databinding"
3-
api "org.graceframework:grace-web-gsp"
4-
api "org.graceframework:grace-plugin-validation"
5-
api "org.graceframework:grace-datastore-core:$gormVersion"
6-
api "org.graceframework:grace-datastore-gorm:$gormVersion"
7-
api "org.graceframework:grace-scaffolding-core:$scaffoldingVersion"
8-
api "org.apache.commons:commons-lang3"
9-
compileOnly "org.graceframework:grace-boot"
10-
compileOnly "jakarta.servlet:jakarta.servlet-api"
2+
api project(":grace-scaffolding-core")
3+
api project(":grace-web-databinding")
4+
api project(":grace-web-gsp")
5+
api project(":grace-plugin-validation")
6+
implementation libs.grace.datastore.core
7+
implementation libs.grace.datastore.gorm
8+
implementation libs.grace.datastore.gorm.support
9+
api libs.commons.lang3
10+
compileOnly libs.jakarta.servlet
1111

12-
api "org.springframework.boot:spring-boot-autoconfigure"
13-
annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor"
14-
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
12+
api libs.spring.boot.autoconfigure
13+
annotationProcessor libs.spring.boot.autoconfigureProcessor
14+
annotationProcessor libs.spring.boot.configurationProcessor
1515

16-
testImplementation "org.apache.groovy:groovy-dateutil"
17-
testImplementation "org.graceframework:grace-test-support"
18-
testImplementation "org.graceframework.plugins:scaffolding:$scaffoldingVersion"
19-
testImplementation "org.spockframework:spock-core", {
20-
exclude group: "org.junit.platform", module: "junit-platform-engine"
21-
}
22-
testImplementation "net.bytebuddy:byte-buddy"
23-
testImplementation "org.objenesis:objenesis:$objenesisVersion"
24-
testImplementation "org.apache.groovy:groovy-test-junit5:${groovyVersion}", {
25-
exclude group: "org.junit.platform", module: "junit-platform-launcher"
26-
exclude group: "org.junit.jupiter", module: "junit-jupiter-engine"
27-
}
28-
testImplementation "org.junit.jupiter:junit-jupiter-api"
29-
testImplementation "org.junit.platform:junit-platform-runner"
30-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
31-
testImplementation("org.jodd:jodd-wot:$joddWotVersion") {
32-
exclude module: 'slf4j-api'
33-
exclude module: 'asm'
34-
}
16+
testImplementation project(":grace-test")
17+
testImplementation project(":grace-test-support")
18+
testImplementation libs.bytebuddy
19+
testImplementation libs.objenesis
20+
testImplementation libs.groovy.dateutil
21+
testImplementation libs.jodd.wot
3522
}

grace-plugin-fields/src/main/groovy/grails/plugin/formfields/BeanPropertyAccessor.groovy

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
/*
2-
* Copyright 2012 Rob Fletcher
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package grails.plugin.formfields
1817

19-
import grails.core.GrailsDomainClass
2018
import org.grails.scaffolding.model.property.Constrained
2119
import org.grails.datastore.mapping.model.PersistentEntity
2220
import org.grails.datastore.mapping.model.PersistentProperty
2321
import org.springframework.validation.FieldError
2422

23+
/**
24+
* @author Rob Fletcher
25+
* @since 2024.0.0
26+
*/
2527
interface BeanPropertyAccessor {
2628

2729
/**
@@ -49,13 +51,6 @@ interface BeanPropertyAccessor {
4951
*/
5052
Class getBeanType()
5153

52-
/**
53-
* @return the GORM domain type of `beanType`. This will be null if `beanType` is not a domain class.
54-
* @deprecated use {@link #getEntity}
55-
*/
56-
@Deprecated
57-
GrailsDomainClass getBeanClass()
58-
5954
/**
6055
* @return the GORM domain type of `beanType`. This will be null if `beanType` is not a domain class.
6156
*/

grace-plugin-fields/src/main/groovy/grails/plugin/formfields/BeanPropertyAccessorImpl.groovy

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/*
2-
* Copyright 2012 Rob Fletcher
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package grails.plugin.formfields
1817

1918
import java.lang.constant.Constable
@@ -27,21 +26,22 @@ import groovy.transform.Canonical
2726
import groovy.transform.CompileStatic
2827
import org.apache.commons.lang3.ClassUtils
2928
import grails.core.*
30-
import grails.plugins.VersionComparator
3129
import org.grails.datastore.gorm.GormEntity
3230
import org.grails.datastore.mapping.dirty.checking.DirtyCheckable
3331
import org.grails.datastore.mapping.model.PersistentEntity
3432
import org.grails.datastore.mapping.model.PersistentProperty
3533
import org.grails.scaffolding.model.property.Constrained
3634
import org.springframework.validation.FieldError
3735

38-
36+
/**
37+
* @author Rob Fletcher
38+
* @since 2024.0.0
39+
*/
3940
@Canonical(includes = ['beanType', 'propertyName', 'propertyType'])
4041
class BeanPropertyAccessorImpl implements BeanPropertyAccessor {
4142

4243
Object rootBean
4344
Class rootBeanType
44-
GrailsDomainClass beanClass
4545
Class beanType
4646
String pathFromRoot
4747
String propertyName
@@ -52,23 +52,6 @@ class BeanPropertyAccessorImpl implements BeanPropertyAccessor {
5252
PersistentEntity entity
5353
GrailsApplication grailsApplication
5454

55-
/**
56-
* Since Grails 2.3 blank values that are provided for String properties are
57-
* <a href="http://grails.1312388.n4.nabble.com/Grails-2-3-Data-Binding-String-Trimming-And-Null-Conversions-td4645255.html">converted to null by default</a>
58-
*/
59-
@Lazy
60-
private boolean convertBlanksToNull = { ->
61-
62-
String applicationGrailsVersion = grailsApplication.metadata.getGrailsVersion()
63-
boolean isAtLeastGrails2Point3 = new VersionComparator().compare(applicationGrailsVersion, '2.3') != -1
64-
65-
if (isAtLeastGrails2Point3) {
66-
getDataBindingConfigParamValue('convertEmptyStringsToNull') && getDataBindingConfigParamValue('trimStrings')
67-
} else {
68-
false
69-
}
70-
}()
71-
7255
/**
7356
* Returns the effective value of a a boolean config param from the <code>grails.databinding</code> node
7457
* @param paramName
@@ -113,6 +96,7 @@ class BeanPropertyAccessorImpl implements BeanPropertyAccessor {
11396
} else if (propertyType == String) {
11497
// if the property prohibits nulls and blanks are converted to nulls, then blanks will be prohibited even if a blank
11598
// constraint does not exist
99+
boolean convertBlanksToNull = getDataBindingConfigParamValue('convertEmptyStringsToNull') && getDataBindingConfigParamValue('trimStrings')
116100
boolean hasBlankConstraint = constraints?.hasAppliedConstraint(ConstrainedProperty.BLANK_CONSTRAINT)
117101
boolean blanksImplicityProhibited = !hasBlankConstraint && !constraints?.nullable && convertBlanksToNull
118102
!constraints?.nullable && (!constraints?.blank || blanksImplicityProhibited)

grace-plugin-fields/src/main/groovy/grails/plugin/formfields/DelegatingBeanPropertyAccessorImpl.groovy

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package grails.plugin.formfields
33
import java.lang.constant.Constable
44
import java.lang.constant.ConstantDesc
55

6-
import grails.core.GrailsDomainClass
76
import grails.gorm.Entity
87
import grails.util.GrailsNameUtils
98
import grails.validation.Validateable
@@ -58,12 +57,6 @@ class DelegatingBeanPropertyAccessorImpl implements BeanPropertyAccessor {
5857
pathFromRoot
5958
}
6059

61-
@Override
62-
@Deprecated
63-
GrailsDomainClass getBeanClass() {
64-
throw new UnsupportedOperationException()
65-
}
66-
6760
@Override
6861
PersistentEntity getEntity() {
6962
domainProperty.domainClass

grace-plugin-fields/src/main/groovy/grails/plugin/formfields/FieldsGrailsPlugin.groovy

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,20 +16,19 @@
1616
package grails.plugin.formfields
1717

1818
import grails.plugins.Plugin
19+
import grails.util.GrailsUtil
1920

2021
class FieldsGrailsPlugin extends Plugin {
2122

2223
static final String CONSTRAINTS_EVALULATOR_BEAN_NAME = 'validateableConstraintsEvaluator'
2324

25+
def version = GrailsUtil.getGrailsVersion()
2426
def grailsVersion = '2023.0.0 > *'
2527

2628
def loadAfter = ['domainClass']
2729
def title = 'Grace Fields Plugin'
2830
def description = 'Provides customizable form-field rendering based on overrideable GSP template'
29-
def documentation = 'https://github.com/graceframework/grace-fields'
3031

31-
def license = 'APACHE'
32-
def issueManagement = [system: 'Github', url: 'https://github.com/graceframework/grace-fields/issues']
33-
def scm = [url: 'https://github.com/graceframework/grace-fields']
32+
def providedArtefacts = [FormFieldsTagLib]
3433

3534
}

grace-plugin-fields/src/main/groovy/grails/plugin/formfields/FormFieldsTagLib.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
/*
2-
* Copyright 2012 Rob Fletcher
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package grails.plugin.formfields
1817

1918
import grails.core.GrailsApplication
2019
import groovy.transform.CompileStatic
2120
import groovy.xml.MarkupBuilder
2221
import org.apache.commons.lang3.StringUtils
22+
23+
import grails.gsp.TagLib
2324
import org.grails.buffer.FastStringWriter
2425
import org.grails.datastore.mapping.model.MappingContext
2526
import org.grails.datastore.mapping.model.PersistentEntity
@@ -41,6 +42,7 @@ import java.text.NumberFormat
4142

4243
import static FormFieldsTemplateService.toPropertyNameFormat
4344

45+
@TagLib
4446
class FormFieldsTagLib {
4547
static final namespace = 'f'
4648

grace-plugin-fields/src/main/groovy/grails/plugin/formfields/PropertyPathAccessor.groovy

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package grails.plugin.formfields
217

318
import grails.gorm.validation.DefaultConstrainedProperty
@@ -16,8 +31,11 @@ import org.springframework.validation.FieldError
1631
import static grails.plugin.formfields.BeanPropertyAccessorFactory.stripIndex
1732
import static java.util.Collections.EMPTY_LIST
1833
import static org.apache.commons.lang3.StringUtils.substringAfterLast
19-
import grails.core.*
2034

35+
/**
36+
* @author Rob Fletcher
37+
* @since 2024.0.0
38+
*/
2139
@CompileStatic
2240
@Canonical(includes = ['beanType', 'propertyName', 'propertyType'])
2341
class PropertyPathAccessor implements BeanPropertyAccessor {
@@ -37,7 +55,6 @@ class PropertyPathAccessor implements BeanPropertyAccessor {
3755

3856
Object getRootBean() { null }
3957
Class getRootBeanType() { null }
40-
GrailsDomainClass getBeanClass() { null }
4158
PersistentEntity getEntity() { null }
4259
List<Class> getBeanSuperclasses() { EMPTY_LIST }
4360
List<Class> getPropertyTypeSuperclasses() { EMPTY_LIST }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<plugin name='fields'>
2+
<type>grails.plugin.formfields.FieldsGrailsPlugin</type>
3+
</plugin>

0 commit comments

Comments
 (0)