Two Laptop Bag*
The moose likes Struts and the fly likes STRUTS  VALIDATOR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "STRUTS  VALIDATOR" Watch "STRUTS  VALIDATOR" New topic
Author

STRUTS VALIDATOR

Giulietta Blumarine
Ranch Hand

Joined: Dec 03, 2004
Posts: 59
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

Joined: Dec 03, 2004
Posts: 59
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

Joined: Dec 03, 2004
Posts: 59
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: STRUTS VALIDATOR
 
Similar Threads
Struts Validation not working
What Are the Causes for Validation Not Doing Anything?
STRUTS VALIDATION OF AN INTEGER FIELD (please, answer me!!!)
Error using Struts Validator
Problem with Struts validator