Command object with @Delegate object does not bind params to delegate
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Steps to Reproduce
1. Clone https://github.com/chrisbrookes/grails3-delegate-cmd-binding-issue.git
2. cd app; grails run-app
3. In a browser go to http://localhost:8080/testCmdBind
4. Enter a value in the Bind Me textfield, click Go.
5. Check debug logs for `cmd: app.MyCmd(app.MyDelegate(...))`
### Expected Behaviour
`MyCmd` should have its delegate's `bindMe` property bound to the incoming param.
### Actual Behaviour
No binding is done on the delegate object.
Also tried with explicit `bindData` call in index action.
### Environment Information
- **Operating System**: Ubuntu 16
- **Grails Version:** 3.2.11
- **JDK Version:** Java 8
### Example Application
- https://github.com/chrisbrookes/grails3-delegate-cmd-binding-issue.git
For reference, here's the controller / cmd code:
```groovy
package app
import groovy.transform.ToString
class TestCmdBindController
{
def index(MyCmd cmd)
{
log.debug "params: $params"
log.debug "cmd: $cmd"
bindData(cmd, params)
log.debug "cmd after bindData: $cmd"
render(view: 'index', model: [cmd: cmd])
}
}
@ToString
class MyCmd
{
@Delegate
MyDelegate delegate = new MyDelegate()
static constraints = {}
}
@ToString
class MyDelegate
{
String bindMe
}
```
Contributor guide
Research direction
Start with the example application and run the Grails app using the listed reproduction steps. Inspect TestCmdBindController, MyCmd, and MyDelegate, including the parameter binding and explicit bindData call. Done means the delegate's bindMe property is populated from the submitted field and the debug output reflects the bound value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100