• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2 Integer Validation not working

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Experts, I am trying to add Integer validation to the my Struts 2 application.
Here is what I have done

<validators>
<validator type="int">
<param name="fieldName">zipCode</param>
<message>Zip Code needs to be a valid number </message>
</validator>
</validators>

I have already set validate="true" in the <s:form> tag
This is successfully generating the java script code at my JSP. But when I see the generated code. The validation code for my field is hacing code



Not sure why this code is coming

if (false || false) {


Due to this it will not do validation for this field.

Any clue? Am I doing something wrong here? Please help.
 
Ranch Hand
Posts: 83
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks like the Struts 2 "int" type validator does the range check. It uses IntRangeFieldValidator which is checking for integer range only.

I think its still beta so they may be fixing some issues. It should be working as you are expecting but if this does not work then have a workaround by using regular expression for number validation in your case it should work fine as you have zip code which need not be checked for the range.

Here is a Example Code which demonstrate how you can use regular expression validation for number validation in Struts 2.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic