This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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?
 
jQuery in Action, 2nd edition
 
subject: validation: how to make int and double validations work ?
 
Similar Threads
short-circuit attribute not working in validation file
Struts2 Validation - Number?
Multiple field validation in Struts2 Validation using validation.xml file
Struts 2 Integer Validation not working
struts2 xml validator error message placement?