tags:

views:

29

answers:

1

Hi ,

I want to do a validation of password length specifying minlength should be 15 ,i am using struts validtion.xml to do this,i am able to validate required fields but not length ,where i am going wrong.The code is like

validation.xml

 <formset>
     <form name="LoginForm">
      <field property="password" depends="required,minlen">
       <arg key="label.password" position="0"/>    
                 <arg key="${var:minlen}" resource="false" />
           <var>
             <var-name>minlen</var-name>
             <var-value>3</var-value>
           </var>
      </field>
      <field property="userName" depends="required">
       <arg key="label.userName" position="0"/>
      </field>
     </form>
    </formset>

jsp is like

<html:form action="/Login?method=login">
<body>
<table cellspacing="0" cellpadding="0" borde="0" style="width:300px;text-align:left;">
 <tr><td colspan=2><html:errors /></td></tr>
 <tr>
  <th><bean:message key="label.userName"/></th>
  <td><html:text name="LoginForm" property="userName" /></td>
 </tr>
 <tr>
  <th><bean:message key="label.password"/></th>
  <td><html:password name="LoginForm" property="password" /></td>
 </tr>
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
 <tr>
  <td colspan="2" align="center"><html:submit styleClass="submit" value="Login" style="width:60px; text-align:center"/></td>
 </tr>
</table>
</body>
</html:form>

Please tel me how to do this ?

A: 

Your validation.xml should be:

<field property="password" depends="required,minlength">
    <arg0 key="label.password" position="0"/>
    <arg1 name="minlength" key="${var:minlength}" resource="false"/>
    <var>
    <var-name>minlength</var-name>
    <var-value>3</var-value>
</var>
</field>

check the section "Standard Built In Validations" in http://struts.apache.org/1.2.4/userGuide/dev_validator.html

juanp