I have used this several times.
The id parameter is bound to your command like any other field. There is no special behavior in this particular field.
Now, if you send a value for the id field, which is incompatible with the type of the identifier field of your team, then the field will not be associated. You will not get a ClassCastException or anything like that. You just get a null value for the field.
I remember that I saw something complicated: if you have id in your URL (for example, controller / action / id) and in your form, the id from the URL takes precedence.
So, if your form has the correct hidden field for ID
<field type="hidden" name="id" value="1"/>
but the action is somehow superimposed on your form
<g:form action="doSometing" id="some-incompatible-value">...</g:form>
What would you get in the controller:
params.id = "some-incompatible-value"
This would make it impossible to convert Grails to your id parameter long or int, and your command object would have
command.id = null
So, I would advise: start over and rewrite your form from scratch and make sure that the value in your form from your controller params.id is compatible with the type of field of your command.
Let me know how this happens.
Vincent Giger
Vincent giguère
source share