tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yansheng Lin" <yansheng....@silvacom.com>
Subject commons-validator validates empty field when it's not required
Date Mon, 23 Feb 2004 20:19:40 GMT
Hi, 

(should've posted this message on 'commons' to get more answers, ah well, hope
there is enough talents in this pool to grind my petty problem into the dust).

As the title suggested, somehow my validator is trying to validate the
'minlength' of every single field no matter whether I set depends="required" or
not.  It seems that all the empty fields are submited by the browser.  Based on
what's stated in validator documentation:  since browser will not submit empty
fields, any field that isn't required will skip all validations if the fields is
null or has a length of zero.  But my browser is doing the exact opposite.  Here
is my form:

<form name="ManageForm" method="post"
action="/Manage.do;jsessionid=26CB107EF9925FB8EEDD4F1223FD89D9"
enctype="multipart/form-data">
<input type="text" name="hInput" value="">
<input type="submit" value="submit" >
</form>

-- in validation.xml --
   <formset>
      <!-- Forms -->
      <form name="ManageTranslateForm">
         <field property="hInput"
             depends="minlength">
               <arg0 key="hInput.displayname"/>
		   <arg1 name="minlength" key="${var:minlength}"
resource="false"/>
                     <var>
                       <var-name>minlength</var-name>
                       <var-value>6</var-value>
                     </var>
         </field>
      </form>
    </formset>

-- in validator-rules.xml --
      <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=""
                  msg="errors.minlength">

I don't know how required() could be invoked when it's not set on this
particular field.  Also if browser do sumbit empty fields, then something is
wrong with the 'required' validator.  But the fact that I have used the
validator successfully before contradicts that conclusion.  But it's kind of
vague in w3 recommendation on whether or not the browser should support this
behaviour:
	If a control doesn't have a current value when the form is submitted,
user agents are not required to treat it as a successful control. 

Any idea greatly appreciated!

-Yan


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


Mime
View raw message