You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/11/11 19:31:22 UTC
svn commit: r1034026 -
/myfaces/commons/trunk/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/TypedNumberConverter.java
Author: lu4242
Date: Thu Nov 11 18:31:21 2010
New Revision: 1034026
URL: http://svn.apache.org/viewvc?rev=1034026&view=rev
Log:
Sync with core (MYFACES-2970 f:convertNumber conversion is not symmetric when currencyCode and currencySymbol are used and MYFACES-1890 Numberconverter has issue with bigdecimal)
Modified:
myfaces/commons/trunk/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/TypedNumberConverter.java
Modified: myfaces/commons/trunk/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/TypedNumberConverter.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/TypedNumberConverter.java?rev=1034026&r1=1034025&r2=1034026&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/TypedNumberConverter.java (original)
+++ myfaces/commons/trunk/myfaces-commons-converters/src/main/java/org/apache/myfaces/commons/converter/TypedNumberConverter.java Thu Nov 11 18:31:21 2010
@@ -18,6 +18,7 @@
*/
package org.apache.myfaces.commons.converter;
+import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
@@ -183,7 +184,22 @@ public class TypedNumberConverter implem
format.setParseIntegerOnly(_integerOnly);
DecimalFormat df = (DecimalFormat)format;
- //df.setParseBigDecimal(true);
+
+ // The best we can do in this case is check if there is a ValueExpression
+ // with a BigDecimal as returning type , and if that so enable BigDecimal parsing
+ // to prevent loss in precision, and do not break existing examples (since
+ // in those cases it is expected to return Double). See MYFACES-1890 and TRINIDAD-1124
+ // for details
+ ValueExpression valueBinding = uiComponent.getValueExpression("value");
+ if (valueBinding != null)
+ {
+ Class<?> destType = valueBinding.getType(facesContext.getELContext());
+ if (destType != null && BigDecimal.class.isAssignableFrom(destType))
+ {
+ df.setParseBigDecimal(true);
+ }
+ }
+
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
boolean changed = false;
if(dfs.getGroupingSeparator() == '\u00a0')
@@ -192,6 +208,9 @@ public class TypedNumberConverter implem
df.setDecimalFormatSymbols(dfs);
changed = true;
}
+
+ formatCurrency(format);
+
try
{
return format.parse(value);