Using the Play! Framework, I have a field that requires the user to enter a numeric value greater than zero. In my controller, I have something like this:
public static void save(@Min(value = 1, message = "Age must be greater than zero") int age) {
...
}
This works as expected and the error message is shown if the user enters in zero or less. However, if the user enters in something like abc then the message shown on the screen says Incorrect value.
What do I have to do to make the UI show a more user friendly error message in this situation?
You can try to use a regular Expression that checks if the parameter is numeric.
A workaround may also be to override the message for incorrect values.
Put this in your messages file.
However this will change the message for the whole application and may not always be appropriate.
Another possible solution is to clear the validations and then invoke all validations you want in your save-Method:
This will clear all validations that have been done automatically. Then you can invoke the validations yourself.