You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2011/01/11 01:06:22 UTC
svn commit: r1057418 - in
/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs:
Core.js CoreFormat.js NumberConverter.js
Author: jwaldman
Date: Tue Jan 11 00:06:21 2011
New Revision: 1057418
URL: http://svn.apache.org/viewvc?rev=1057418&view=rev
Log:
TRINIDAD-1997 DEFAULT LONG CONVERTER ROUNDOFF ERRORS
Thanks to Jing Wu for the patch
Modified:
myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js?rev=1057418&r1=1057417&r2=1057418&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js Tue Jan 11 00:06:21 2011
@@ -5024,3 +5024,42 @@ TrUIUtils._getStyle = function(element,
}
return '';
}
+
+/**
+ * Check whether a number string can be converted or not.
+ *
+ * javascript numbers are really doubles, and as such can accurately support 15 digits, see
+ * http://en.wikipedia.org/wiki/Double_precision
+ *
+ * this means in certain cases a long value that will be fine on the server will be
+ * rounded by the client converter. To avoid this parse the number string, and don't
+ * try to convert on the client if the number of digits is greater than 15.
+ *
+ * Of course this is an imperfect fix, but since the vast majority of
+ * numbers entered are less than 15 digits numbers are still converted on the client most
+ * of the time.
+ */
+TrUIUtils.isNumberConvertible = function(numberString)
+{
+ if (numberString != null)
+ {
+ var nums = 0;
+
+ for (var i = 0; i < numberString.length; i++)
+ {
+ var charCode = numberString.charCodeAt(i);
+ // the charcode for "0" is 48, the charcode for "9" is 57, so count anything between these
+ // as a number
+ if (charCode > 47 && charCode < 58)
+ {
+ nums++;
+ }
+ }
+
+ if (nums > 15)
+ return false;
+ }
+
+ return true;
+}
+
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?rev=1057418&r1=1057417&r2=1057418&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Tue Jan 11 00:06:21 2011
@@ -101,16 +101,24 @@ TrLongConverter.prototype.getAsObject =
label
)
{
- return _decimalParse(numberString,
- this._message,
- "org.apache.myfaces.trinidad.convert.LongConverter",
- this._maxPrecision,
- this._maxScale,
- this._maxValue,
- this._minValue,
- label,
- null);
+ if(TrUIUtils.isNumberConvertible(numberString))
+ {
+ return _decimalParse(numberString,
+ this._message,
+ "org.apache.myfaces.trinidad.convert.LongConverter",
+ this._maxPrecision,
+ this._maxScale,
+ this._maxValue,
+ this._minValue,
+ label,
+ null);
+ }
+ else
+ {
+ return undefined;
+ }
}
+
function TrShortConverter(
message,
maxPrecision,
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js?rev=1057418&r1=1057417&r2=1057418&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js Tue Jan 11 00:06:21 2011
@@ -331,37 +331,10 @@ TrNumberConverter.prototype._isConvertib
// The locale attribute is now supported on convertNumber.
if (this._pattern != null)
return false;
-
- // javascript numbers are really doubles, and as such can accurately support 15 digits, see
- // http://en.wikipedia.org/wiki/Double_precision
- //
- // this means in certain cases a long value that will be fine on the server will be
- // rounded by the client converter. To avoid this parse the number string, and don't
- // try to convert on the client if the number of digits is greater than 15.
- //
- // Of course this is an imperfect fix, but since the vast majority of
- // numbers entered are less than 15 digits numbers are still converted on the client most
- // of the time.
- if (numberString != null)
- {
- var nums = 0;
-
- for (var i = 0; i < numberString.length; i++)
- {
- var charCode = numberString.charCodeAt(i);
- // the charcode for "0" is 48, the charcode for "9" is 57, so count anything between these
- // as a number
- if (charCode > 47 && charCode < 58)
- {
- nums++;
- }
- }
-
- if (nums > 15)
- return false;
- }
-
- return true;
+
+ // check other common criteria as well.
+ return TrUIUtils.isNumberConvertible(numberString);
+
}
/**