防止 Grails fieldValue 格式化数字

Prevent Grails fieldValue from formatting numbers

我在 Fields plugin . This plugin calls the fieldValue tag on numbers at line 862 here. FormFieldsTagLib.groovy 中使用 Grails 3.3.9。出于某种原因,此 fieldValue 标记使用逗号格式化数字,即使 en_US 语言环境的默认格式为“0”,也不应添加逗号。调用 fieldValue 标签时是否有配置阻止 Grails 添加逗号?现在,如果 bean 有一个值为 2019 的 Integer 属性,它将呈现为 2,019.

要重新创建,您只需执行 grails create-app myapp,然后使用整数 属性 创建域 class。启用脚手架,保存记录并将其取回。您会看到其中有逗号。

我通过调试ValidationTaglib.groovy中的代码找到了逗号背后的原因。它在 PropertyEditor 上调用 asText 方法,如下所示:ValidationTagLib . Grails registers property editors here. So to fix it, you'll have to define your own Editor for Integer. You'll have to define your own PropertyEditorRegistrar to register the custom Editor, then declare it as a Spring bean as defined here