You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by wt...@apache.org on 2016/06/22 16:06:06 UTC
svn commit: r1749730 -
/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
Author: wtlucy
Date: Wed Jun 22 16:06:06 2016
New Revision: 1749730
URL: http://svn.apache.org/viewvc?rev=1749730&view=rev
Log:
MYFACES-4050: Validators not invoked for empty selectManyCheckbox components
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java?rev=1749730&r1=1749729&r2=1749730&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java Wed Jun 22 16:06:06 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);
}
@@ -428,4 +430,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;
+ }
}