Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

required validation on integer field not working

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to validate a text field that takes number. While creating the form I said the parameter type is Integer. I have a required validation on it. If I don't type anything and press submit it automatically enters 0 for the field.

Has anyone come accross this problem? How to solve this?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can fix this by making a change to your web.xml file. Add the following to the <servlet> stanza you used to define the Struts ActionServlet:


This will make it so that an integer evaluates to blank instead of zero, and will therefore be caught by the required validation.
 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks. appreciate your reply. I have one more issue. I want the user to enter only numbers in the field.

if I enter alphabets and I press enter it just clears the field but does not show me error ...only number is allowed. It always shows field is required.

<field property="gid" depends="required,mask">
<msg name = "required" key = "errors.required" bundle = "gmessage" />

<msg name = "mask" key = "errors.invalid" bundle = "gmessage" />
<arg0 key="display.gid" />

<var>
<var-name>mask</var-name>
<var-value>^[0-9]*$</var-value>
</var>

</field>
[ February 09, 2007: Message edited by: shah rah ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the primary reason that it is best to use Strings for all editable fields on your form.

- Brent
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can change the mask for integer validation (or short or whatever you need)

[ February 10, 2007: Message edited by: Joan Horta Tosas ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic