myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wtl...@apache.org
Subject svn commit: r1749729 - /myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectMany.java
Date Wed, 22 Jun 2016 16:05:44 GMT
Author: wtlucy
Date: Wed Jun 22 16:05:44 2016
New Revision: 1749729

URL: http://svn.apache.org/viewvc?rev=1749729&view=rev
Log:
MYFACES-4050: Validators not invoked for empty selectManyCheckbox components

Modified:
    myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectMany.java

Modified: myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectMany.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectMany.java?rev=1749729&r1=1749728&r2=1749729&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectMany.java
(original)
+++ myfaces/core/branches/2.1.x/api/src/main/java/javax/faces/component/UISelectMany.java
Wed Jun 22 16:05:44 2016
@@ -27,6 +27,7 @@ import java.util.Iterator;
 
 import javax.el.ValueExpression;
 import javax.faces.application.FacesMessage;
+import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.convert.ConverterException;
@@ -341,8 +342,9 @@ public class UISelectMany extends UIInpu
             return;
         }
 
-        // run the validators only if there are item values to validate
-        if (hasValues)
+        // run the validators if there are item values to validate, or 
+        // if we are required to validate empty fields
+        if (hasValues  || shouldValidateEmptyFields(context))
         {
             _ComponentUtils.callValidators(context, this, convertedValue);
         }
@@ -442,4 +444,45 @@ public class UISelectMany extends UIInpu
             }
         }
     }
+
+    // Copied from javax.faces.component.UIInput
+    private boolean shouldValidateEmptyFields(FacesContext context)
+    {
+        ExternalContext ec = context.getExternalContext();
+        Boolean validateEmptyFields = (Boolean) ec.getApplicationMap().get(VALIDATE_EMPTY_FIELDS_PARAM_NAME);
+
+        if (validateEmptyFields == null)
+        {
+             String param = ec.getInitParameter(VALIDATE_EMPTY_FIELDS_PARAM_NAME);
+
+             // 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 validateEmptyFields;
+    }
 }



Mime
View raw message