apache / apache/grails-core

domainSuffix ignored by views

Open
#14,297 0 comments 4 reactions 0 assignees View on GitHub
relates-to: scaffolding
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Copied from https://github.com/grails/grails-core/issues/10023 - apparently github doesn't support moving issues.

TL;DR
In Grails 3, grails.scaffolding.templates.domainSuffix is ignored by scaffolding views, both static and dynamic. This breaks apps upgrading from 2.x.

Environment:
Windows 8.1
jdk1.8.0_92
Grails 3.1.7

I have upgraded an app from 2.4 to 3.1.7 and notice issues with scaffolding. In my 2.4 app, I had in Config.groovy:

`grails.scaffolding.templates.domainSuffix = 'Instance'`

And I'm pretty sure that was added by default, which means this will affect a lot of people.

In my controller's index method (rendered by default with the list scaffolding view), this line worked:

```
List companies = Company.findAll()
respond companies, model: [companyInstanceCount: Company.count()]
```

In the dynamic view, `companies` corresponded with `companyInstanceList`, and the view rendered perfectly.

After upgrading to 3.1.7, both the main body (list) and pagination were empty. After testing, I discovered the following:
1. domainSuffix appears to change the **model** name, but **not** the corresponding variables in the view. Instead of expecting companyInstanceList and companyInstanceCount, it wants companyList and companyCount
2. adding domainSuffix to application.yml as such did not change this.

```

grails:
codegen:
defaultPackage: com.madeupname.web
scaffolding:
templates:
domainSuffix: Instance
```

I tested by explicitly setting model variable names::

```
[companyInstanceList: companies, companyInstanceCount: Company.count()]
```

domainSuffix is **also ignored in static scaffolding**, as views generated with

```
grails generate-views com.madeupname.web.Company
```

look for companyList, not companyInstanceList, etc.

Right now, the workaround is to:
1. remove domainSuffix from config
2. Update all your controllers to remove the word Instance from model variable names

If this was intentional, the Upgrading and Scaffolding sections of the documentation should be updated to prevent confusion. But this is a breaking change, so I assume it's a bug.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with grails.scaffolding.templates.domainSuffix in application.yml, checking both dynamic views and views generated by grails generate-views. Trace how the scaffolding model names are passed to each view; done means static and dynamic views consistently honor the configured suffix, or the relevant upgrading and scaffolding documentation is corrected if the behavior is intentional.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.