grails-views icon indicating copy to clipboard operation
grails-views copied to clipboard

Display Tag does not render 'id', 'dateCreated' and 'lastUpdated' fields.

Open codeconsole opened this issue 5 years ago • 0 comments

Following the work done on grails/fields#257

You would except to be able to do something like this: <f:display bean="challenge" except="[]" />

and see id, dateCreated, and dateUpdated

Furthermore, I believe you would expect FormFieldsTagLib.resolvePersistentProperties to call domainModelService.geOutputProperties(domainClass)`

as it is defined as The list of {@link DomainProperty} instances that are to be visible

I realize that there should be some synergy between the edit and the view page and such a change could be followed by requiring attrs.except like was done for grails/fields#257 However, it is a feature I am constantly looking for because I have no way of knowing the dateCreated and dateUpdated as well as the id (unless I look at the url).

Since the display tag already calls FormFieldsTagLib.resolvePersistentProperties implementing this fix is as simple as

  1. Creating an enum FormFieldsTagLib.PropertiesType = { LIST, OUTPUT, INPUT }
  2. Changing private List<PersistentProperty> resolvePersistentProperties(PersistentEntity domainClass, Map attrs, boolean list = false) { to private List<PersistentProperty> resolvePersistentProperties(PersistentEntity domainClass, Map attrs, PropertiesType propertiesType = PropertiesType.INPUT ) {

and modifying the method properties = propertiesType == PropertiesType.LIST ? domainModelService.getListOutputProperties(domainClass) : propertiesType == PropertiesType.INPUT ? domainModelService.getInputProperties(domainClass) : domainModelService.getOutputProperties(domainClass) // If 'except' is not set, but 'list' is, exclude 'id', 'dateCreated' and 'lastUpdated' by default List<String> blacklist = attrs.containsKey('except') ? getList(attrs.except) : (propertiesType == PropertiesType.LIST ? ['id', 'dateCreated', 'lastUpdated'] : [])

Then changing the existing calls to FormFieldsTagLib.resolvePersistentProperties in 2 locations

def display = { attrs, body ->

resolvePersistentProperties(domainClass, attrs, PropertiesType.OUTPUT)

and private List<String> resolvePropertyNames(PersistentEntity domainClass, Map attrs) {

List<String> properties = resolvePersistentProperties(domainClass, attrs, PropertiesType.INPUT)*.name

codeconsole avatar Sep 21 '20 06:09 codeconsole