W
wsn
Unregistered / Unconfirmed
GUEST, unregistred user!
在 struts 里做过 floatRange Validate的朋友请进,我这里有好多输入域
是float类型的把值限定在 0.00 和 9999999.99之间,一开始的时候一切都
很正常,但是后来做边界测试的时候发现如果输入10000000竟然也能通过
Validate,真是把我搞晕了。
-------------------------------------------
我的代码是这样写的:
<field property="f006" depends="maxlength,float,floatRange">
<arg0 key="AO010_T10_form.f006"/>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<arg1 name="floatRange" key="${var:min}" resource="false"/>
<arg2 name="floatRange" key="${var:max}" resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
<var>
<var-name>min</var-name>
<var-value>0.00</var-value>
</var>
<var>
<var-name>max</var-name>
<var-value>9999999.99</var-value>
</var>
</field>
-------------------------------------------
apache.org 上down的 validator-rules.xml 是这样写的,我看不出又任何问题
<validator name="floatRange"
classname="org.apache.struts.validator.FieldChecks"
method="validateFloatRange"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="float"
msg="errors.range">
<javascript><![CDATA[
function validateFloatRange(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oRange = new floatRange();
for (x in oRange) {
var field = form[oRange[x][0]];
if ((field.type == 'text' ||
field.type == 'textarea') &&
(field.value.length > 0)) {
var fMin = parseFloat(oRange[x][2]("min"));
var fMax = parseFloat(oRange[x][2]("max"));
var fValue = parseFloat(field.value);
alert(fValue);
alert(fMin);
alert(fMax);
if (!(fValue >= fMin &&
fValue <= fMax)) {
if (i == 0) {
focusField = field;
}
fields[i++] = oRange[x][1];
isValid = false;
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('/n'));
}
return isValid;
}]]>
</javascript>
</validator>
难道这个是bug吗?我怎么改呢
是float类型的把值限定在 0.00 和 9999999.99之间,一开始的时候一切都
很正常,但是后来做边界测试的时候发现如果输入10000000竟然也能通过
Validate,真是把我搞晕了。
-------------------------------------------
我的代码是这样写的:
<field property="f006" depends="maxlength,float,floatRange">
<arg0 key="AO010_T10_form.f006"/>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<arg1 name="floatRange" key="${var:min}" resource="false"/>
<arg2 name="floatRange" key="${var:max}" resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
<var>
<var-name>min</var-name>
<var-value>0.00</var-value>
</var>
<var>
<var-name>max</var-name>
<var-value>9999999.99</var-value>
</var>
</field>
-------------------------------------------
apache.org 上down的 validator-rules.xml 是这样写的,我看不出又任何问题
<validator name="floatRange"
classname="org.apache.struts.validator.FieldChecks"
method="validateFloatRange"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="float"
msg="errors.range">
<javascript><![CDATA[
function validateFloatRange(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oRange = new floatRange();
for (x in oRange) {
var field = form[oRange[x][0]];
if ((field.type == 'text' ||
field.type == 'textarea') &&
(field.value.length > 0)) {
var fMin = parseFloat(oRange[x][2]("min"));
var fMax = parseFloat(oRange[x][2]("max"));
var fValue = parseFloat(field.value);
alert(fValue);
alert(fMin);
alert(fMax);
if (!(fValue >= fMin &&
fValue <= fMax)) {
if (i == 0) {
focusField = field;
}
fields[i++] = oRange[x][1];
isValid = false;
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('/n'));
}
return isValid;
}]]>
</javascript>
</validator>
难道这个是bug吗?我怎么改呢