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 17:15:43 UTC
svn commit: r1033980 - in /myfaces:
core/branches/1.1.x/api/src/main/java/javax/faces/convert/NumberConverter.java
core/branches/1.1.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java
current11/pom.xml
Author: lu4242
Date: Thu Nov 11 16:15:43 2010
New Revision: 1033980
URL: http://svn.apache.org/viewvc?rev=1033980&view=rev
Log:
MYFACES-2970 f:convertNumber conversion is not symmetric when currencyCode and currencySymbol are used
Added:
myfaces/core/branches/1.1.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java
Modified:
myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/NumberConverter.java
myfaces/current11/pom.xml
Modified: myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/NumberConverter.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/NumberConverter.java?rev=1033980&r1=1033979&r2=1033980&view=diff
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/NumberConverter.java (original)
+++ myfaces/core/branches/1.1.x/api/src/main/java/javax/faces/convert/NumberConverter.java Thu Nov 11 16:15:43 2010
@@ -98,15 +98,43 @@ public class NumberConverter
{
NumberFormat format = getNumberFormat(facesContext);
format.setParseIntegerOnly(_integerOnly);
+
+ DecimalFormat df = (DecimalFormat)format;
+ //df.setParseBigDecimal(true);
+ DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
+ boolean changed = false;
+ if(dfs.getGroupingSeparator() == '\u00a0')
+ {
+ dfs.setGroupingSeparator(' ');
+ df.setDecimalFormatSymbols(dfs);
+ changed = true;
+ }
+
+ formatCurrency(format);
+
try
{
return format.parse(value);
}
catch (ParseException e)
{
+ if(changed)
+ {
+ dfs.setGroupingSeparator('\u00a0');
+ df.setDecimalFormatSymbols(dfs);
+ }
+ try
+ {
+ return format.parse(value);
+ }
+ catch (ParseException pe)
+ {
+
throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
CONVERSION_MESSAGE_ID,
new Object[]{uiComponent.getId(),value}), e);
+
+ }
}
}
}
Added: myfaces/core/branches/1.1.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.1.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java?rev=1033980&view=auto
==============================================================================
--- myfaces/core/branches/1.1.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java (added)
+++ myfaces/core/branches/1.1.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java Thu Nov 11 16:15:43 2010
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package javax.faces.convert;
+
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import java.util.Locale;
+
+public class NumberConverterTest extends AbstractJsfTestCase
+{
+ private NumberConverter mock;
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(NumberConverterTest.class);
+ }
+
+ public NumberConverterTest(String name)
+ {
+ super(name);
+ }
+
+ public void setUp()
+ {
+ super.setUp();
+
+ mock = new NumberConverter();
+ }
+
+ public void tearDown()
+ {
+ super.tearDown();
+
+ mock = null;
+ }
+ /*
+ * temporarily comment out tests that fail, until Matthias Wessendorf has time to investigate
+ */
+ public void testFranceLocaleWithNonBreakingSpace()
+ {
+ mock.setLocale(Locale.FRANCE);
+ FacesContext.getCurrentInstance().getViewRoot().setLocale(Locale.GERMANY);
+ UIInput input = new UIInput();
+ mock.setType("currency");
+ String stringValue = mock.getAsString(facesContext, input, new Double(12345.68d));
+ Number number = (Number) mock.getAsObject(FacesContext.getCurrentInstance(), input, "12\u00a0345,68 \u20AC");
+ assertNotNull(number);
+ }
+ public void testFranceLocaleWithoutNonBreakingSpace()
+ {
+ mock.setLocale(Locale.FRANCE);
+ FacesContext.getCurrentInstance().getViewRoot().setLocale(Locale.GERMANY);
+ UIInput input = new UIInput();
+ mock.setType("currency");
+ Number number = (Number) mock.getAsObject(FacesContext.getCurrentInstance(), input, "12 345,68 \u20AC");
+ assertNotNull(number);
+ }
+
+ /**
+ * EUR12,345.68
+ */
+ public void testUSLocaleUsingEURCurrencyCode()
+ {
+ facesContext.getViewRoot().setLocale(Locale.US);
+ mock.setLocale(Locale.US);
+ UIInput input = new UIInput();
+ mock.setType("currency");
+ mock.setCurrencyCode("EUR");
+ Number testValue = new Double(12345.68d);
+ String stringValue = mock.getAsString(facesContext, input, testValue);
+ Number number = (Number) mock.getAsObject(facesContext, input, stringValue);
+ assertNotNull(number);
+ assertEquals(testValue, number);
+ }
+
+ /**
+ * 12,345.68
+ */
+ public void testUKLocaleUsingEURCurrencyCode()
+ {
+ facesContext.getViewRoot().setLocale(Locale.US);
+ mock.setLocale(Locale.UK);
+ UIInput input = new UIInput();
+ mock.setType("currency");
+ mock.setCurrencyCode("EUR");
+ Number testValue = new Double(12345.68d);
+ String stringValue = mock.getAsString(facesContext, input, testValue);
+ Number number = (Number) mock.getAsObject(facesContext, input, stringValue);
+ assertNotNull(number);
+ assertEquals(testValue, number);
+ }
+
+ /**
+ * 12.345,68
+ */
+ public void testGermanyLocaleUsingEURCurrencyCode()
+ {
+ facesContext.getViewRoot().setLocale(Locale.US);
+ mock.setLocale(Locale.GERMANY);
+ UIInput input = new UIInput();
+ mock.setType("currency");
+ mock.setCurrencyCode("EUR");
+ Number testValue = new Double(12345.68d);
+ String stringValue = mock.getAsString(facesContext, input, testValue);
+ Number number = (Number) mock.getAsObject(facesContext, input, stringValue);
+ assertNotNull(number);
+ assertEquals(testValue, number);
+ }
+
+ public void testCurrencyPattern()
+ {
+ facesContext.getViewRoot().setLocale(Locale.US);
+ mock.setLocale(Locale.US);
+ UIInput input = new UIInput();
+ mock.setPattern("\u00A4 ###,###.###");
+ Number testValue = new Double(12345.68d);
+ String stringValue = mock.getAsString(facesContext, input, testValue);
+ Number number = (Number) mock.getAsObject(facesContext, input, stringValue);
+ assertNotNull(number);
+ assertEquals(testValue, number);
+ }
+
+ public void testCurrencyPattern2()
+ {
+ facesContext.getViewRoot().setLocale(Locale.US);
+ mock.setLocale(Locale.GERMANY);
+ UIInput input = new UIInput();
+ mock.setPattern("\u00A4 ###,###.###");
+ mock.setCurrencyCode("USD"); //Since currency is , but we are using USD currency code, the output is USD 12.345,68
+ Number testValue = new Double(12345.68d);
+ String stringValue = mock.getAsString(facesContext, input, testValue);
+ Number number = (Number) mock.getAsObject(facesContext, input, stringValue);
+ assertNotNull(number);
+ assertEquals(testValue, number);
+ }
+
+}
Modified: myfaces/current11/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/current11/pom.xml?rev=1033980&r1=1033979&r2=1033980&view=diff
==============================================================================
--- myfaces/current11/pom.xml (original)
+++ myfaces/current11/pom.xml Thu Nov 11 16:15:43 2010
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.myfaces</groupId>
+ <artifactId>myfaces</artifactId>
+ <version>9</version>
+ </parent>
+
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.myfaces</groupId>
<artifactId>myfaces-base</artifactId>