• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Validator-Validating an Integer Form Field

 
Anitha Lingam
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an integer form field. In my ActionForm I extend the ValidatorForm and i'm trying to Validate that field.
My validation.xml for that integer field looks like this
<field property="vcoord"
depends="required,integer">
<arg0 key="vcoord"/>
</field>
When i enter my jsp page, this field is automatically set to 0.
Even when i remove the 0 and perform the operation , validation doesn't happen. Instead the field is set back to 0.
The same problem occurs when i try to enter a string to the integer field and validate it. i.e..it doesn't validate telling that it is not an integer instead the value is set back to 0.
Can anybody help??
Thanks in advance.
 
sandy gupta
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the jsp where you define the field, do you have a value=0?
 
Anitha Lingam
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i haven't set any value
This is how it looks
<html:text property="vcoord" maxlength="5" size="6"/>
 
Jimmy Soh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
solution
 
Jimmy Soh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, it should be convertNull instead of converNull.
 
Giulietta Blumarine
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I have the same problem of Anitha Lingam.
I haven't understood the solution.
Can anybody help me?Anita, have you resolved?
Thank you
 
Giulietta Blumarine
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have modified my web.xml following your indications:

<init-param>
<param-name >convertNull </param-name >
<param-value >true </param-value >
</init-param >

OK, the text form value is not converted to zero but to null.
But If I insert in the form a character, for example, can I have a message type "int required"???

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic