Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STRUTS VALIDATOR

 
Giulietta Blumarine
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic