myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gcrawf...@apache.org
Subject svn commit: r1239429 - /myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/NumberConverter.java
Date Thu, 02 Feb 2012 01:26:45 GMT
Author: gcrawford
Date: Thu Feb  2 01:26:45 2012
New Revision: 1239429

URL: http://svn.apache.org/viewvc?rev=1239429&view=rev
Log:
TRINIDAD-2144 NumberConverter formatHint does not consider trinidad-config.xml settings for
decimal-separator, number-grouping-separator


Thanks to Kentaro

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/NumberConverter.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/NumberConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/NumberConverter.java?rev=1239429&r1=1239428&r2=1239429&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/NumberConverter.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/NumberConverter.java
Thu Feb  2 01:26:45 2012
@@ -786,6 +786,31 @@ public class NumberConverter extends jav
     if (pattern == null)
       return null;
     
+    RequestContext reqCtx = RequestContext.getCurrentInstance();
+    String type = getType();
+    Locale locale = _getLocale(reqCtx, context);
+    DecimalFormat df = (DecimalFormat) _getNumberFormat(pattern, type, locale, reqCtx);
+    if (dfs == null)
+    {
+      dfs = df.getDecimalFormatSymbols();
+    }
+    
+    // If grouping and decimal separator have been customized then
+    // show them in the hint so that it's less confusing for the user.
+    char decSep = dfs.getDecimalSeparator();
+    char groupSep = dfs.getGroupingSeparator();
+
+    char[] patternArr = pattern.toCharArray();
+    for (int i = 0; i < patternArr.length; i++)
+    {
+      char c = patternArr[i];
+      if (c == '\u002E')
+        patternArr[i] = decSep;
+      else if (c == '\u002C')
+        patternArr[i] = groupSep;
+    }
+    pattern = new String(patternArr);
+    
     // If the pattern contains the generic currency sign, replace it with the localized 
     // currency symbol (if one exists), so that when the pattern is displayed (such as in
an error 
     // message), it is more meaningful to the user.
@@ -798,16 +823,6 @@ public class NumberConverter extends jav
     if (idx == -1)
       return pattern;
     
-    if (dfs == null)
-    {
-      String type = getType();
-      RequestContext reqCtx = RequestContext.getCurrentInstance();
-      Locale locale = _getLocale(reqCtx, context);
-      NumberFormat fmt = _getNumberFormat(pattern, type, locale, reqCtx);
-      DecimalFormat df = (DecimalFormat) fmt;
-      dfs = df.getDecimalFormatSymbols();
-    }
-    
     if (idx + 1 < pattern.length() && pattern.charAt(idx + 1) == '\u00A4')
     {
       // Matcher.quoteReplacement ensures that the replacement string is properly escaped.



Mime
View raw message