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 18:04:25 UTC
svn commit: r1034000 -
/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java
Author: lu4242
Date: Thu Nov 11 17:04:25 2010
New Revision: 1034000
URL: http://svn.apache.org/viewvc?rev=1034000&view=rev
Log:
MYFACES-1890 Numberconverter has issue with bigdecimal
Modified:
myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java
Modified: myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java?rev=1034000&r1=1033999&r2=1034000&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java (original)
+++ myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java Thu Nov 11 17:04:25 2010
@@ -18,6 +18,7 @@
*/
package javax.faces.convert;
+import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
@@ -25,6 +26,7 @@ import java.text.ParseException;
import java.util.Currency;
import java.util.Locale;
+import javax.el.ValueExpression;
import javax.faces.component.StateHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -109,7 +111,22 @@ public class NumberConverter
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')