Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes  validation: how to make int and double validations work ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark " validation: how to make int and double validations work ?" Watch " validation: how to make int and double validations work ?" New topic
Author

validation: how to make int and double validations work ?

Boris Romashov
Ranch Hand

Joined: Feb 23, 2009
Posts: 38
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 23, 2009
Posts: 38
How can I handle this errors?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: validation: how to make int and double validations work ?