Groovy/Grails autoconvert NaN string to double field

笑着哭i 提交于 2020-01-06 03:25:06

问题


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:


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.



来源:https://stackoverflow.com/questions/10751338/groovy-grails-autoconvert-nan-string-to-double-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!