You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2010/11/04 15:40:17 UTC

svn commit: r1031007 - /myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java

Author: martinkoci
Date: Thu Nov  4 14:40:17 2010
New Revision: 1031007

URL: http://svn.apache.org/viewvc?rev=1031007&view=rev
Log:
MYFACES-2920: UISelectOne/UISelectMany validateValue: Before comparing each option, coerce the option value type to the type of component's value 
https://issues.apache.org/jira/browse/MYFACES-2920

Modified:
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java?rev=1031007&r1=1031006&r2=1031007&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/el/MockExpressionFactory.java Thu Nov  4 14:40:17 2010
@@ -152,6 +152,27 @@ public class MockExpressionFactory exten
             throw new IllegalArgumentException("Cannot convert " + object
                     + " to Character");
         }
+        
+        if (targetType.isEnum()) {
+            if (object == null || "".equals(object)) {
+                return null;
+            }
+            if (targetType.isAssignableFrom(object.getClass())) {
+                return (Enum) object;
+            }
+            
+            if (!(object instanceof String)) {
+            	throw new IllegalArgumentException("Cannot convert " + object + " to Enum");
+            }
+
+            Enum<?> result;
+            try {
+                 result = Enum.valueOf(targetType, (String) object);
+                 return result;
+            } catch (IllegalArgumentException iae) {
+            	throw new IllegalArgumentException("Cannot convert " + object + " to Enum");
+            }
+        }
 
         // Is the specified value type-compatible already?
         if ((object != null) && targetType.isAssignableFrom(object.getClass()))