Groovy/Grails autoconvert NaN string to double fie

2019-08-06 18:30发布

I want to let users edit a field with double data in Grails view. I want to allow Double.NaN (to void values).

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.

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.

What method is callled for conversion? Whats the key to let it autoconvert to a double?

1条回答
混吃等死
2楼-- · 2019-08-06 19:00

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.

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.

查看更多
登录 后发表回答