commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Elie Medeiros" <nc...@networkphotographers.com>
Subject DynaValidatorForm.validate() does not seemt o validate Integers when called from DispatchAction [Re: Problem validating form manually in DispatchAction]
Date Fri, 10 Oct 2003 12:13:41 GMT
I poseted this tot he Struts mailing list - not sure if it is better to
post it here ot there (not sure whether the error is dues to Struts or
Validator...)

It seems that the DynaValidatorForm.validate() method when called from
Struts' DispatchAction does validate Strings, but not Integers....
For some reason, when validation is carried out this way it only seems
to find errors in one of the form fields - however, if I set the
validate="true" property in the struts-module-config.xml file,
validation does seem to be carried out properly, which suggests to me
that I did not make a mistake in the validation configuration. Since I
want to use DispatchAction however, I can't use validate="true", as I
need to validate the form selectively for one of the methods only. 

I have tried using ValidatorLookupdispatchForm, but can't use it as
Struts 1.1 (which I am using) seems to have a bug with the set-property
tag in the module-config.xml file. Also tried latest version of Struts
(1.1, was using 1.1rc3) and of the validator (1.0, 1.02, latest nightly
build). My code is as follows - pretty straightforward:

<Action>
		DynaValidatorForm thisForm = (DynaValidatorForm)form;
		ActionErrors errors=thisForm.validate(mapping,request);
		
                Integer var1= (Integer)thisForm.get("var1");
                (... get more form vars...)
		
		//if errors, back to form
		if (!errors.isEmpty()) {
			saveErrors(request, errors);

			return mapping.getInputForward();
		 }
</Action>

<struts-module-config.xml>
	<action input="/editUserDetails.vm" name="details_form"
			path="/details" 
			scope="request"
			parameter="method"
			type="com.inc.modules.users.DetailsAction"
			validate="false">
		<!-- not working in struts 1.1
		<set-property property="validateMethod(doEdit)" value="true"/>
		<set-property property="validateMethod(viewEdit)" value="false"/>
		<set-property property="validateMethod(viewDetails)" value="false"/> 
		-->
		   <forward name="view" path="/viewUserDetails.vm" redirect="false"/>
	</action>
</struts-module-config.xml>

<validation-module.xml>
	<form name="details_form">
		<field
				property="var1"
				depends="required,integer">
					<msg name="required" key="errors.required"/>
					<arg0 name="required" key="forms.var1"/>
					<msg name="integer" key="errors.integer"/>
					<arg0 name="integer" key="forms.var1"/>
		</field>
	</form>
</validation-module.xml>

I have spent almost 2 days trying to figure ways of getting around this
- anyone have any ideas?

Thanks,
Elie




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message