Groovy / Grails将NaN字符串自动转换为双字段 [英] Groovy/Grails autoconvert NaN string to double field
问题描述
我想让用户在Grails视图中编辑具有双重数据的字段。我想允许Double.NaN(无效值)。
I want to let users edit a field with double data in Grails view. I want to allow Double.NaN (to void values).
有一个特殊的字符看起来像一个钻石,里面有一个问号(在HTML中),就像NaN,但是 - 用户不会发现他们的密钥。
There is a special char looking like a diamond with a question mark in it (in HTML) that acts like NaN, but - well - the users wont find that on their keys.
在Java中,它可以与 Double.valueOf(NaN)
。但是在输入字段中输入NaN会抛出一个IllegalArgumentException,表示NaN是一个不可扩展的数字。
In Java it works with Double.valueOf("NaN")
. But typing NaN in the input field will throw a IllegalArgumentException saying "NaN" is an Unparseable Number.
转换的方法是什么?如果你使用 Double $ c,那么关键是让它自动转换为双倍?
What method is callled for conversion? Whats the key to let it autoconvert to a double?
推荐答案
$ c>而不是code> double 在域类或命令对象中,并在约束中使用 nullable:true
'作为'没有数据'的价值。
If you use Double
instead of double
in the domain class or command object, and use nullable:true
in the constraints ´null´ acts as 'no data' value.
如果你真的想坚持NaN,你必须注册一个自定义的属性,请参阅 http://ishanf.tumblr.com/post/434379583/custom-property-editor-for-grails 。
If you really want to stick to NaN, you have to register a custom propertyeditor, see http://ishanf.tumblr.com/post/434379583/custom-property-editor-for-grails.
这篇关于Groovy / Grails将NaN字符串自动转换为双字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!