robfletcher/grails-fields — Issue #55: Integers with 0 value aren't rendered
Author: edgescope
Created: 2012-03-09 21:04:56+00:00
State: open

In the FormFieldsTagLib.buildModel method, the map's value entry isn't being calculated correctly for Numbers with a value of 0.

e.g. If I have a model with an int attribute, then when that field is displayed, it's rendered as null.

The cause appears to be the use of groovy truth for the value determination logic. i.e. Around line 131
value ?: valueDefault - returns false for Integer 0.

For a Number's case, I think the correct logic would be a null check. e.g.
value: (value != null) ? value : valueDefault

...but I don't know if that's applicable for all object types like String. Might need to have one or more checks based on type.?