default min/max validation messages round to integer

167 views
Skip to first unread message

Alison Winters

unread,
Nov 16, 2010, 4:43:40 PM11/16/10
to play-framework
Currently the default messages for validation of @Range, @Min and @Max
are rounded to integer:

validation.range=Not in the range %2$d through %3$d
validation.min=Cannot be lower than %2$d
validation.max=Cannot be greater than %2$d

This isn't strictly correct because the checks use doubles, not ints.
This means for cases where you have annotated @Min(0.1) you will see
an error message "Cannot be lower than 0" instead of "Cannot be lower
than 0.1". Or worse - @Max(2.4) will show "Cannot be higher than 2".
This could easily be fixed by switching to $f in the messages file,
but unfortunately that uses six digits of decimal precision by
default, which is probably not what most people want.

What is the correct way to solve this problem in Play? Would it be to
have an annotation that points at a custom message, like
@Min(value=0.1,message="validation.min.0.1")?

I think this behavior should probably be mentioned in the
documentation somewhere, since it isn't necessarily intuitive. Either
that or perhaps the checks could be changed to have both integer and
floating point versions?

Alison

GrailsDeveloper

unread,
Nov 17, 2010, 2:42:33 AM11/17/10
to play-framework
You could set in your message.properties
validation.range=Not in the range %2$f through %3$f
and so on.

Unfortunately you don't can get the String you put into the
Annotation. Another possibility is

@Min(value=0.1,message="Cannot be lower than 0.1") or the way you
suggested with an entry in your message.properties.

Niels
Reply all
Reply to author
Forward
0 new messages