Struts Flot Double 传0 报错,解决办法
这个错是 XWork 里面的一个 Bug,在 XWork - Version 2.1.3 里面已经解决。管方的 Bug是
[XW-677] - double/float parameters not converted when <= 0
管方的解决方式是 :
Conversion to double/float types does not occur if the value is less than or equal to zero.
This is due to a bug in com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java in the isInRange method which takes the lower bound of the value to be Double/Float.MIN_VALUE. In fact MIN_VALUE is the smallest positive non-zero number and not the smallest negative number.
Our suggested fix is to negate the value of MAX_VALUE.
?
下面是管网的修改方式,所以介意升级 Xwork 的版本,如果不想升级的话,就把 Xwork 里面的文件按下面这个修改作一下改动。
?
Index: src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java===================================================================--- src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java(revision 1925)+++ src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java(working copy)@@ -428,11 +428,13 @@ try { if (double.class == toType || Double.class == toType) { bigValue = new BigDecimal(stringValue);- lowerBound = BigDecimal.valueOf(Double.MIN_VALUE);+ // Double.MIN_VALUE is the smallest positive non-zero number+ lowerBound = BigDecimal.valueOf(Double.MAX_VALUE).negate(); upperBound = BigDecimal.valueOf(Double.MAX_VALUE); } else if (float.class == toType || Float.class == toType) { bigValue = new BigDecimal(stringValue);- lowerBound = BigDecimal.valueOf(Float.MIN_VALUE);+ // Float.MIN_VALUE is the smallest positive non-zero number+ lowerBound = BigDecimal.valueOf(Float.MAX_VALUE).negate(); upperBound = BigDecimal.valueOf(Float.MAX_VALUE); } else if (byte.class == toType || Byte.class == toType) { bigValue = new BigInteger(stringValue);
?
用这样的方式,比在 Struts2 上面作过滤要简单的多。