You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Shah, Akshay" <Ak...@atosorigin.com> on 2005/02/19 13:07:57 UTC

Struts validator woes : maxLength minLength

Hii All,

I am using Struts 1.1, DynaValidatorForm.
The required validation is working fine.
The minlength and maxlength validations are not working for me. ie, wutever
be the case they always throw the error.
and I am completely clueless as to why is this happening. Any thoughts

Any thoughts?

Regards,
Akshay

My Source 


validator-rules.xml
      <validator name="maxlength"
            classname="org.apache.struts.validator.FieldChecks"
               method="validateMaxLength"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends=""
                  msg="errors.maxlength"/>


validation.xml
    <formset>

        <!-- An example form -->
       <form name="parentForm">
           <field property="userName" depends="required,maxlength">
				 <arg0 key="message.username"/>
				 <arg1 name="maxlength"
key="${var:maxLength}" resource="false"/>
				 <var>
					<var-name>maxLength</var-name>
					<var-value>6</var-value>
				 </var>
           </field>
       </form>
    </formset>



struts-en_US.xml
....

    <form-beans>
		  <form-bean
            name="parentForm"
            type="org.apache.struts.validator.DynaValidatorForm">
			<form-property name="userName"
type="java.lang.String"/>
		</form-bean>
    <form-beans>
|
|
|
	  <action	path="/register"
				name="parentForm"
				validate="true"
				scope="session"
	
type="com.kandoo.profile.action.registerAction"
				input="/profile/pages/register.jsp">
				<forward name="success"
path="/en_US/home/pages/home.jsp" contextRelative="true"/>
				<forward name="addChild"
path="/en_US/profile/pages/childProfile.jsp" contextRelative="true"/>
				<forward name="initial"
path="/en_US/profile/pages/register.jsp" contextRelative="true"/>
	 </action>





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


Re: Struts validator woes : maxLength minLength

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Try changing your <var-name>'s to all lower case

<var-name>maxlength</var-name>

Niall
----- Original Message ----- 
From: "Shah, Akshay" <Ak...@atosorigin.com>
To: <us...@struts.apache.org>
Sent: Saturday, February 19, 2005 12:07 PM
Subject: Struts validator woes : maxLength minLength


> Hii All,
>
> I am using Struts 1.1, DynaValidatorForm.
> The required validation is working fine.
> The minlength and maxlength validations are not working for me. ie,
wutever
> be the case they always throw the error.
> and I am completely clueless as to why is this happening. Any thoughts
>
> Any thoughts?
>
> Regards,
> Akshay
>
> My Source
>
>
> validator-rules.xml
>       <validator name="maxlength"
>             classname="org.apache.struts.validator.FieldChecks"
>                method="validateMaxLength"
>          methodParams="java.lang.Object,
>                        org.apache.commons.validator.ValidatorAction,
>                        org.apache.commons.validator.Field,
>                        org.apache.struts.action.ActionErrors,
>                        javax.servlet.http.HttpServletRequest"
>               depends=""
>                   msg="errors.maxlength"/>
>
>
> validation.xml
>     <formset>
>
>         <!-- An example form -->
>        <form name="parentForm">
>            <field property="userName" depends="required,maxlength">
> <arg0 key="message.username"/>
> <arg1 name="maxlength"
> key="${var:maxLength}" resource="false"/>
> <var>
> <var-name>maxLength</var-name>
> <var-value>6</var-value>
> </var>
>            </field>
>        </form>
>     </formset>
>
>
>
> struts-en_US.xml
> ....
>
>     <form-beans>
>   <form-bean
>             name="parentForm"
>             type="org.apache.struts.validator.DynaValidatorForm">
> <form-property name="userName"
> type="java.lang.String"/>
> </form-bean>
>     <form-beans>
> |
> |
> |
>   <action path="/register"
> name="parentForm"
> validate="true"
> scope="session"
>
> type="com.kandoo.profile.action.registerAction"
> input="/profile/pages/register.jsp">
> <forward name="success"
> path="/en_US/home/pages/home.jsp" contextRelative="true"/>
> <forward name="addChild"
> path="/en_US/profile/pages/childProfile.jsp" contextRelative="true"/>
> <forward name="initial"
> path="/en_US/profile/pages/register.jsp" contextRelative="true"/>
> </action>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



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


Re: Struts validator woes : maxLength minLength

Posted by Erik Weber <er...@mindspring.com>.
A little-publicized feature (ahem) of Struts 1.1 Validator is that arg1 
has to be paired with minlength and arg2 has to be paired with 
maxlength, as I understand it (last I remember this was true). I don't 
know if this has been changed in more recent versions. You are pairing 
maxlength with arg1 in the example posted. Also, I think the var-name 
needs to be "maxlength", not "maxLength".

Erik


Shah, Akshay wrote:

>Hii All,
>
>I am using Struts 1.1, DynaValidatorForm.
>The required validation is working fine.
>The minlength and maxlength validations are not working for me. ie, wutever
>be the case they always throw the error.
>and I am completely clueless as to why is this happening. Any thoughts
>
>Any thoughts?
>
>Regards,
>Akshay
>
>My Source 
>
>
>validator-rules.xml
>      <validator name="maxlength"
>            classname="org.apache.struts.validator.FieldChecks"
>               method="validateMaxLength"
>         methodParams="java.lang.Object,
>                       org.apache.commons.validator.ValidatorAction,
>                       org.apache.commons.validator.Field,
>                       org.apache.struts.action.ActionErrors,
>                       javax.servlet.http.HttpServletRequest"
>              depends=""
>                  msg="errors.maxlength"/>
>
>
>validation.xml
>    <formset>
>
>        <!-- An example form -->
>       <form name="parentForm">
>           <field property="userName" depends="required,maxlength">
>				 <arg0 key="message.username"/>
>				 <arg1 name="maxlength"
>key="${var:maxLength}" resource="false"/>
>				 <var>
>					<var-name>maxLength</var-name>
>					<var-value>6</var-value>
>				 </var>
>           </field>
>       </form>
>    </formset>
>
>
>
>struts-en_US.xml
>....
>
>    <form-beans>
>		  <form-bean
>            name="parentForm"
>            type="org.apache.struts.validator.DynaValidatorForm">
>			<form-property name="userName"
>type="java.lang.String"/>
>		</form-bean>
>    <form-beans>
>|
>|
>|
>	  <action	path="/register"
>				name="parentForm"
>				validate="true"
>				scope="session"
>	
>type="com.kandoo.profile.action.registerAction"
>				input="/profile/pages/register.jsp">
>				<forward name="success"
>path="/en_US/home/pages/home.jsp" contextRelative="true"/>
>				<forward name="addChild"
>path="/en_US/profile/pages/childProfile.jsp" contextRelative="true"/>
>				<forward name="initial"
>path="/en_US/profile/pages/register.jsp" contextRelative="true"/>
>	 </action>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>

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