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:16:34 UTC

svn commit: r1033981 - in /myfaces: core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java core/branches/1.2.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java current12/pom.xml

Author: lu4242
Date: Thu Nov 11 16:16:33 2010
New Revision: 1033981

URL: http://svn.apache.org/viewvc?rev=1033981&view=rev
Log:
MYFACES-2970 f:convertNumber conversion is not symmetric when currencyCode and currencySymbol are used

Modified:
    myfaces/core/branches/1.2.x/api/src/main/java/javax/faces/convert/NumberConverter.java
    myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java
    myfaces/current12/pom.xml

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=1033981&r1=1033980&r2=1033981&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 16:16:33 2010
@@ -118,6 +118,9 @@ public class NumberConverter
                   df.setDecimalFormatSymbols(dfs);
                   changed = true;
                 }
+                
+                formatCurrency(format);
+                
                 try
                 {
                     return format.parse(value);

Modified: myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java?rev=1033981&r1=1033980&r2=1033981&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java (original)
+++ myfaces/core/branches/1.2.x/api/src/test/java/javax/faces/convert/NumberConverterTest.java Thu Nov 11 16:16:33 2010
@@ -44,9 +44,6 @@ public class NumberConverterTest extends
         super.setUp();
 
         mock = new NumberConverter();
-        mock.setLocale(Locale.FRANCE);
-        FacesContext.getCurrentInstance().getViewRoot().setLocale(Locale.GERMANY);
-
     }
 
     protected void tearDown() throws Exception
@@ -55,23 +52,105 @@ public class NumberConverterTest extends
 
         mock = null;
     }
-/*
- * temporarily comment out tests that fail, until Matthias Wessendorf has time to investigate
+    /*
+     * 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");
-        Number number = (Number) mock.getAsObject(FacesContext.getCurrentInstance(), input, "12\u00a0345,68 €");
+        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 = 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 = 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");
-        Number number = (Number) mock.getAsObject(FacesContext.getCurrentInstance(), input, "12 345,68 €");
+        mock.setCurrencyCode("EUR");
+        Number testValue = 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 = 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 = 12345.68d;
+        String stringValue = mock.getAsString(facesContext, input, testValue);
+        Number number = (Number) mock.getAsObject(facesContext, input, stringValue);
         assertNotNull(number);
+        assertEquals(testValue, number);        
     }
-*/
+
 }

Modified: myfaces/current12/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/current12/pom.xml?rev=1033981&r1=1033980&r2=1033981&view=diff
==============================================================================
--- myfaces/current12/pom.xml (original)
+++ myfaces/current12/pom.xml Thu Nov 11 16:16:33 2010
@@ -1,30 +1,36 @@
-<?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">
-
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.myfaces</groupId>
-  <artifactId>myfaces-base</artifactId>
-  <packaging>pom</packaging>
-  <version>1.2.10-SNAPSHOT</version>
-  <name>Build Project</name>
-  <url>http://myfaces.apache.org</url>
-
-  <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/myfaces/current12</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/myfaces/current12</developerConnection>
-    <url>http://svn.apache.org/viewcvs.cgi/myfaces/current12</url>
-  </scm>
-
-  <modules>
-    <module>shared</module>
-    <module>core</module>
-    <!--
-    <module>test-webapp</module>
-    -->
-  </modules>
-
-  <build>
-  	<defaultGoal>install</defaultGoal>
-  </build>
-
+<?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>
+  <packaging>pom</packaging>
+  <version>1.2.10-SNAPSHOT</version>
+  <name>Build Project</name>
+  <url>http://myfaces.apache.org</url>
+
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/myfaces/current12</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/myfaces/current12</developerConnection>
+    <url>http://svn.apache.org/viewcvs.cgi/myfaces/current12</url>
+  </scm>
+
+  <modules>
+    <module>shared</module>
+    <module>core</module>
+    <!--
+    <module>test-webapp</module>
+    -->
+  </modules>
+
+  <build>
+  	<defaultGoal>install</defaultGoal>
+  </build>
+
 </project>
\ No newline at end of file