开发者

using different formats for BigDecimal in bindData

开发者 https://www.devze.com 2023-01-13 07:53 出处:网络
i have a class class Foo { BigIntegerphase BigDecimalamount BigDecimalpercent } and want to use bindData to map some user input.

i have a class

class Foo {

BigInteger phase

BigDecimal amount

BigDecimal percent

}

and want to use bindData to map some user input.

The user enters data in different formats for amount and percent

i.e. :

  • amount : 100.000,00
  • percent : 75,50%

bindData parses this to

  • amount = 100000 (in GERMAN Locale)
  • percent : 75.5

is there any way to force grails to format domain-fields using different formats? For the example i would use NumberFormat.getNumberInstance for amount and NumberFormat.getPercentInstance for percent using the current Locale....

I tried the CustomEditor thing, but this procedure is type-bound 开发者_运维技巧and will not work on two different formats using the same type...

Anybody any idea? ;)

Thanks, Alex


Using a CustomEditor should work. You just pass a custom date binder that can determine the value being submitted and transform it. In our app for example, we have a custom date binder that transforms a single date field (normally Grails expects the date split into three fields).

0

精彩评论

暂无评论...
验证码 换一张
取 消