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 struts integer validator 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 "struts integer validator" Watch "struts integer validator" New topic
Author

struts integer validator

Jimmy Soh
Greenhorn

Joined: Dec 04, 2003
Posts: 5
What is the simplest way to validate that a user's input is an integer if the underlying data type in the form is int?
My problem is that I have a text field for entering integer values in which a user might accidentally type letters or floating point numbers. Unfortunately, it seems the form automatically sets the value to 0 if the input is invalid. Thus, the struts validator sees 0 instead of the user's actual input, which might have been "afd.04964."
Edward He
Greenhorn

Joined: Mar 17, 2004
Posts: 7
I have the exactly the same problem. Is there anyone have any ideas? Struts don't validate request incomings but the populated forms.
Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
the simplest (depens on your preference):

validation.xml:
add a mask dependency that checks on [0-9] (regex)

if you're more comfortable with java in stead of xml:
add validate() method in the actionform and there you can check if the variable does have chars in it.

In both cases you do need to activate the validator framework by setting it in the struts-config.

If you don't want to use validator framework:
throw error in the action when your variable is null or 0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts integer validator
 
Similar Threads
how to have struts validator run on a combination of form properties?
validation for Inetger type field in Struts
Using struts validator to check onchange events.
STRUTS VALIDATION OF AN INTEGER FIELD (please, answer me!!!)
Integer type validation thru "validation.xml"