Groovy / Grails将NaN字符串自动转换为双字段 [英] Groovy/Grails autoconvert NaN string to double field

查看:227
本文介绍了Groovy / Grails将NaN字符串自动转换为双字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让用户在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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆