Is there a binder for a decimal value that considers locale?

142 views
Skip to first unread message

Renato Oliveira

unread,
Aug 1, 2011, 6:36:55 PM8/1/11
to play-fr...@googlegroups.com
Hi.

It's my first message here. I've tried to find this over the web but I didn't found anything.

I need to format a double value with my locale. It works fine for showing the value on a view for example.

Here in Brazil the a number or currency has this format 9.999,99.

If I set a lang "pt" on my application.conf, the format of a number on a view is fine (9.999,99).

I need something similar to my forms and validation.

If I format the value that I show on the form(so the user can enter the information with the right format), after submit, the validation crashes (invalid number, or something like it).

I there is any binder @As for a decimal value?

Or should I implement one?

Thank you.

Renato



christian sarnataro

unread,
Aug 2, 2011, 3:57:12 AM8/2/11
to play-framework
Did you try with the @Match validation?

http://www.playframework.org/documentation/1.2.2/validation-builtin#match

You could use a pattern like:
pattern = "((^\\d{1,3}(\\.\\d{3})+(,\\d+)?)$)";

Bye

Renato Oliveira

unread,
Aug 2, 2011, 7:20:19 AM8/2/11
to play-framework
Hi Christian.

It will probably solve the validation thing, but I still need to
convert it back to the database pattern with . as a decimal separator.

Thank you.


On 2 ago, 04:57, christian sarnataro <christian.sarnat...@gmail.com>
wrote:
> Did you try with the @Match validation?
>
> http://www.playframework.org/documentation/1.2.2/validation-builtin#m...

GrailsDeveloper

unread,
Aug 2, 2011, 3:00:05 PM8/2/11
to play-framework
I thought the normal binder do this job, but I look into the code and
in deed it doesn't support it. I think you have two options

create a ticket and a patch for the binder class data/binding/
Binder.java line 475

or write your own binder http://www.playframework.org/documentation/1.2.2/controllers#custombinding

Niels
Reply all
Reply to author
Forward
0 new messages