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 2013/09/15 02:28:47 UTC

svn commit: r1523369 - /myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIInput.java

Author: lu4242
Date: Sun Sep 15 00:28:46 2013
New Revision: 1523369

URL: http://svn.apache.org/r1523369
Log:
MYFACES-3746 Cache resolved value of javax.faces.VALIDATE_EMPTY_FIELDS (Thanks to Dennis Hoersch for provide this patch)

Modified:
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIInput.java

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIInput.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIInput.java?rev=1523369&r1=1523368&r2=1523369&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIInput.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIInput.java Sun Sep 15 00:28:46 2013
@@ -503,35 +503,45 @@ public class UIInput extends UIOutput im
         return ((value instanceof String) && (((String) value).length() == 0));
     }
 
+
     private boolean shouldValidateEmptyFields(FacesContext context)
     {
-        ExternalContext extCtx = context.getExternalContext();
-        String validateEmptyFields = (String) extCtx.getInitParameter(VALIDATE_EMPTY_FIELDS_PARAM_NAME);
-        if (validateEmptyFields == null)
-        {
-            validateEmptyFields = (String) extCtx.getApplicationMap().get(VALIDATE_EMPTY_FIELDS_PARAM_NAME);
-        }
+        ExternalContext ec = context.getExternalContext();
+        Boolean validateEmptyFields = (Boolean) ec.getApplicationMap().get(VALIDATE_EMPTY_FIELDS_PARAM_NAME);
 
-        // null means the same as auto.
         if (validateEmptyFields == null)
         {
-            validateEmptyFields = "auto";
-        }
-        else
-        {
-            // The environment variables are case insensitive.
-            validateEmptyFields = validateEmptyFields.toLowerCase();
-        }
+             String param = ec.getInitParameter(VALIDATE_EMPTY_FIELDS_PARAM_NAME);
 
-        if (validateEmptyFields.equals("auto") && _ExternalSpecifications.isBeanValidationAvailable())
-        {
-            return true;
-        }
-        else if (validateEmptyFields.equals("true"))
-        {
-            return true;
+             // null means the same as auto.
+             if (param == null)
+             {
+                 param = "auto";
+             }
+             else
+             {
+                 // The environment variables are case insensitive.
+                 param = param.toLowerCase();
+             }
+
+             if (param.equals("auto") && _ExternalSpecifications.isBeanValidationAvailable())
+             {
+                 validateEmptyFields = true;
+             }
+             else if (param.equals("true"))
+             {
+                 validateEmptyFields = true;
+             }
+             else
+             {
+                 validateEmptyFields = false;
+             }
+
+             // cache the parsed value
+             ec.getApplicationMap().put(VALIDATE_EMPTY_FIELDS_PARAM_NAME, validateEmptyFields);
         }
-        return false;
+
+        return validateEmptyFields;
     }
 
     /**