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/06/11 00:47:17 UTC

svn commit: r953489 - /myfaces/core/trunk/api/src/main/java/javax/faces/convert/EnumConverter.java

Author: lu4242
Date: Thu Jun 10 22:47:16 2010
New Revision: 953489

URL: http://svn.apache.org/viewvc?rev=953489&view=rev
Log:
MYFACES-2739 Pass through String values in EnumConverter.getAsString() (thanks to Jakob Korherr for provide this patch)

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/convert/EnumConverter.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/convert/EnumConverter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/convert/EnumConverter.java?rev=953489&r1=953488&r2=953489&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/convert/EnumConverter.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/convert/EnumConverter.java Thu Jun 10 22:47:16 2010
@@ -24,6 +24,7 @@ import javax.faces.component.UIComponent
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
 
 /**
  * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
@@ -38,6 +39,12 @@ public class EnumConverter implements Co
     public static final String ENUM_ID = "javax.faces.converter.EnumConverter.ENUM";
     public static final String ENUM_NO_CLASS_ID = "javax.faces.converter.EnumConverter.ENUM_NO_CLASS";
 
+    /**
+     * If value is a String instance and this param is true, pass it directly without try any change.
+     */
+    @JSFWebConfigParam(name="org.apache.myfaces.ENUM_CONVERTER_ALLOW_STRING_PASSTROUGH", since="2.0.1", expectedValues="true,false",defaultValue="false")
+    private static final String ALLOW_STRING_PASSTROUGH = "org.apache.myfaces.ENUM_CONVERTER_ALLOW_STRING_PASSTROUGH";
+    
     // TODO: Find a valid generic usage -= Simon Lessard =-
     private Class targetClass;
 
@@ -67,6 +74,13 @@ public class EnumConverter implements Co
 
         if (value == null)
             return null;
+        
+        if (value instanceof String
+                && _isPassThroughStringValues(facesContext))
+        {
+            // pass through the String value
+            return (String) value;
+        }
 
         // check if the value is an instance of the enum class
         if (targetClass.isInstance(value))
@@ -172,5 +186,16 @@ public class EnumConverter implements Co
     {
         _initialStateMarked = true;
     }
+    
+    private boolean _isPassThroughStringValues(FacesContext facesContext)
+    {
+        String param = facesContext.getExternalContext().getInitParameter(ALLOW_STRING_PASSTROUGH);
+        if (param != null)
+        {
+            return param.trim().equalsIgnoreCase("true");
+        }
+        // default: false
+        return false;
+    }
 
 }