Hi! Im using Struts 1.1 RC1 and I want to validate user input. I have a password field that should have at least 6 characters. Therefore, I use the following validator-rule in validator-rules.xml:
<form-validation> <global> <validator name="minlength" classname="org.apache.struts.validator.FieldChecks" method="validateMinLength" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" depends="required" msg="errors.minlength"> <javascript><![CDATA[ function validateMinLength(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oMinLength = new minlength(); for (x in oMinLength) { if (form[oMinLength[x][0]].type == 'text' || form[oMinLength[x][0]].type == 'textarea') { var iMin = parseInt(oMinLength[x][2]("minlength")); if (form[oMinLength[x][0]].value.length < iMin) { if (i == 0) { focusField = form[oMinLength[x][0]]; } fields[i++] = oMinLength[x][1]; bValid = false; } } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return bValid; }]]> </javascript> </validator> <!-- ... --> </global> </form-validation> The validator is used in validation.xml like this: <form-validation> <formset> <form name="logonForm"> <!-- ... --> <field property="password" depends="required,minlength"> <arg0 key="prompt.password"/> <arg1 name="minlength" key="${var:minlength}" resource="false"/> <var> <var-name>minlength</var-name> <var-value>6</var-value> </var> </field> </form> </formset> </form-validation> My logon.jsp: <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <html:html locale="true"> <body> <html:form action="/logon" focus="username" onsubmit="return validateLogonForm(this);"> <table border="0" width="100%"> <!-- ... --> <tr> <th align="right" width="50%"> <bean:message key="prompt.password"/>: </th> <td align="left" width="50%"> <html:password property="password" size="16" maxlength="18" redisplay="false"/> </td> </tr> </table> <!-- Submit and cancel button --> </html:form> <html:javascript formName="logonForm" dynamicJavascript="true" staticJavascript="true" /> </body> </html:html> Last but not least, the entry in the struts-config.xml: <plug-in className="org.apache.struts.validator.ValidatorPlugIn" > <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> My problem is that there is only a server-side validation for the minlength-property. If nothing is entered in the password-field, Javascript-validation (required) works fine (i.e the validation is done on client-side). What am I doing wrong? Thanks for help! Stefan ______________________________________________________________________________ Mit der Auslands-SMS von WEB.DE FreeMail erreichen Sie Ihre Freunde auf der ganzen Welt - http://freemail.web.de/features/?mc=021171 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]