When using command objects it seems I do not get automatic binding of the id field
class somethingCommand {
int id
String A
String B
// some methods here like Domain.get(id)
}
My A and B string get auto-magically data binded from the form properties but not id. The other “hidden fields” of grails like version, dateCreated or lastUpdated also get binded correctly.
My current patched solution is the following:
I resort to defining another hidden id field in my form
<g:hiddenField name="blogId" value="${blog?.id}"/>
And rename id to blogId in the command obect and that works.
This does not seem to be in line with the elegance of Grails. What am I missing in the data binding rules of Command object vs controller?
Following up on this problem:
I ran into the same problem: I had a command with an id parameter. When calling my controller on an action that used the command, all parameters were properly bound except the id.
It turned out that if you have a field called version in your command, the id field will not be assigned.
If you change the name of your version field for something else (ie. readVersion), then the ID will be mapped properly.
Hope that helps,
Vincent Giguere