myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1523369 - /myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/UIInput.java
Date Sun, 15 Sep 2013 00:28:47 GMT
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;
     }
 
     /**



Mime
View raw message