• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation: how to make int and double validations work ?

 
Boris Romashov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say I want to validate field number.

This is a snippet from MyAction-validation.xml


There are 2 cases.
1) If number is field of class String then this validation doesn't work at all
2) If number is field of type int then this validation doesn't work also, but besides if I enter not a number then the following exception is thrown:

java.lang.NoSuchMethodException: setNumber([Ljava.lang.String;)

and instead of my text I see at the page:

Invalid field value for field "number"

So, in both cases int validation doesn't work. The same for double validator.
What to do ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the action property is a string then no, validating it as an integer won't work: strings and ints aren't the same things.

If the action property is an int then as far as I know the int validator works, I've been using it successfully for almost every S2 version. If you enter something that isn't a number then you're getting a type conversion exception. Type conversion messages are added to the field's errors via the "conversion" interceptor.
 
Boris Romashov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I handle this errors?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic