• 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 VALIDATOR

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I'm working with struts validator.
I have a jsp with a simple text field which must send only int values.

<html:text property="rec" name="PaginationForm" value=""/>

I want to block any other values different from int.

Below the code in my STRUTS-config.xml (form declaration, calling action, receiving action)
.....
<form-bean name="PaginationForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="rec" type="java.lang.Integer" />
</form-bean>

<action path="/Tab" type="login.InitAction2" input="/Tab2.do" name="PaginationForm" validate="true" scope="session">
<forward name="success" path="/jsp/stima/EsteemSearchResult.jsp" redirect="false" />
</action>

<action path="/Tab2" type="login.InitAction" >
<forward name="success" path="/jsp/stima/EsteemSearchResult.jsp" redirect="false" />
</action>
....

Below,the code in my validation.xml
<formset>
<form name="PaginationForm">
<field property="rec" depends="required,integer">
<arg0 key="PaginationForm.num_records" />
</field>
</form>
</formset>
</form-validation>


OK, the problem is this:
when I insert in the text field a String, a character or NO value, Struts converts it always in zero.
So the rule "required" is not considered!!!

CAN ANYBODY HELP ME???
THANK YOU
 
Giulietta Blumarine
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SORRY , I must correct an error in the previous message:

the code in my validation.xml:

form name="PaginationForm">
<field property="rec" depends="required,integer">
<arg0 key="PaginationForm.rec" />
</field>

</form>
 
Giulietta Blumarine
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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, so the shown error is "field required".
BUT.... If I insert in the form a character, for example, can I have a message type "int required" instead of the "field required" (shown even if in user inserts something!)???

Thanks
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic