Bug corrections and enhancement proposal for f:display for Grails 3
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
This issue only applies to the grails3 branch. I don't know how to handle a proper pull request, sorry.
- Currently it's not possible to exclude persistent properties in f:display
- Currently it's not possible to include non-persistent properties in f:display
In [FormFieldsTagLib.groovy](https://github.com/grails-fields-plugin/grails-fields/blob/grails3/grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy), in the closure defining the display tag, replace
`def properties = domainClass.persistentProperties.sort(new DomainClassPropertyComparator(domainClass))`
by
`def properties = resolvePersistentProperties(domainClass, attrs)`
The latter method handles exclusions. Note that `render` following this line passes `domainProperties` into the GSP. However, [_list.gsp](https://github.com/grails-fields-plugin/grails-fields/blob/grails3/grails-app/views/templates/_fields/_list.gsp) does not pick up that variable but invokes `domainClass.persistentProperties` again, wasting the work done to select properties. Change to `${domainProperties}` in _list.gsp. That makes 2 changes.
So far only bug corrections. The documentation does not mention it, but the fields plugin picks up a static `scaffold` attribute from the domain class, if present. The value of the attribute must be a map. The `resolvePersistentProperties()` method checks that map and uses its `exclude` key, if defined, to exclude properties from the view.
It is quite easy to add logic to check an `include` key of the same scaffold static property. It may be used to include non-persistent properties in the view. Add the following code after the three `properties.removeAll` calls in the `resolvePersistentProperties` method.
``` groovy
if (scaffoldProp?.include) {
def inclusion = domainClass.properties.findAll {prop ->
scaffoldProp.include.contains(prop.name) && !properties.find {it.name == prop.name}
}
properties.addAll(inclusion)
}
```
The condition makes sure we don't duplicate a property that's already included.
Contributor guide
Research direction
Read the Grails 3 branch implementation in grails-app/taglib/grails/plugin/formfields/FormFieldsTagLib.groovy, especially the display-tag closure and resolvePersistentProperties method, then inspect grails-app/views/templates/_fields/_list.gsp. Done means display honors excluded and included scaffold properties, supports non-persistent included properties, and passes the selected property list through to the GSP.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100