Author: Alex.Kolonitsky
Date: 2009-05-22 09:17:00 -0400 (Fri, 22 May 2009)
New Revision: 14278
Added:
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputSecret.java
Modified:
branches/community/3.3.X/ui/beanValidator/src/main/config/faces/standart-components.xml
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/HibernateValidator.java
Log:
InputSecret: empty values are not validated
https://jira.jboss.org/jira/browse/RF-7180
Modified:
branches/community/3.3.X/ui/beanValidator/src/main/config/faces/standart-components.xml
===================================================================
---
branches/community/3.3.X/ui/beanValidator/src/main/config/faces/standart-components.xml 2009-05-22
13:15:26 UTC (rev 14277)
+++
branches/community/3.3.X/ui/beanValidator/src/main/config/faces/standart-components.xml 2009-05-22
13:17:00 UTC (rev 14278)
@@ -8,10 +8,15 @@
<component-class>org.richfaces.component.html.HtmlInputText</component-class>
</component>
<component>
+ <description><![CDATA[<p>Represents an HTML <code><input
type="password" ...</code> element.</p>]]></description>
+ <display-name>Input Secret</display-name>
+ <component-type>javax.faces.HtmlInputSecret</component-type>
+
<component-class>org.richfaces.component.html.HtmlInputSecret</component-class>
+ </component>
+ <component>
<description><![CDATA[<p>Represents an HTML
<code>textarea</code> element.</p>]]></description>
<display-name>Input Textarea</display-name>
<component-type>javax.faces.HtmlInputTextarea</component-type>
<component-class>org.richfaces.component.html.HtmlInputTextarea</component-class>
-
</component>
</faces-config>
\ No newline at end of file
Added:
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputSecret.java
===================================================================
---
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputSecret.java
(rev 0)
+++
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputSecret.java 2009-05-22
13:17:00 UTC (rev 14278)
@@ -0,0 +1,72 @@
+package org.richfaces.component.html;
+
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.richfaces.validator.FacesBeanValidator;
+
+public class HtmlInputSecret extends javax.faces.component.html.HtmlInputSecret {
+
+ @Override
+ protected void validateValue(FacesContext context, Object newValue) {
+ // If our value is valid, enforce the required property if present
+ if (isValid() && isRequired() && isEmpty(newValue)) {
+ super.validateValue(context, newValue);
+ }
+ // If our value is valid and not empty, call all validators
+ if (isValid()) {
+ Validator[] validators = this.getValidators();
+ if (validators != null) {
+ for (Validator validator : validators) {
+ try {
+ if (validator instanceof FacesBeanValidator
+ || !isEmpty(newValue)) {
+ validator.validate(context, this, newValue);
+ }
+ } catch (ValidatorException ve) {
+ // If the validator throws an exception, we're
+ // invalid, and we need to add a message
+ setValid(false);
+ FacesMessage message;
+ String validatorMessageString = getValidatorMessage();
+
+ if (null != validatorMessageString) {
+ message = new FacesMessage(
+ FacesMessage.SEVERITY_ERROR,
+ validatorMessageString,
+ validatorMessageString);
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ } else {
+ message = ve.getFacesMessage();
+ }
+ if (message != null) {
+ context.addMessage(getClientId(context), message);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static boolean isEmpty(Object value) {
+
+ if (value == null) {
+ return true;
+ } else if ((value instanceof String) && (((String) value).length() <
1)) {
+ return true;
+ } else if (value.getClass().isArray()) {
+ if (0 == java.lang.reflect.Array.getLength(value)) {
+ return true;
+ }
+ } else if (value instanceof List) {
+ if (((List<?>) value).isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Modified:
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java
===================================================================
---
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java 2009-05-22
13:15:26 UTC (rev 14277)
+++
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/component/html/HtmlInputText.java 2009-05-22
13:17:00 UTC (rev 14278)
@@ -80,19 +80,19 @@
private static boolean isEmpty(Object value) {
if (value == null) {
- return (true);
+ return true;
} else if ((value instanceof String) && (((String) value).length() < 1)) {
- return (true);
+ return true;
} else if (value.getClass().isArray()) {
if (0 == java.lang.reflect.Array.getLength(value)) {
- return (true);
+ return true;
}
} else if (value instanceof List) {
- if (((List) value).isEmpty()) {
- return (true);
+ if (((List<?>) value).isEmpty()) {
+ return true;
}
}
- return (false);
+ return false;
}
}
Modified:
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/HibernateValidator.java
===================================================================
---
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/HibernateValidator.java 2009-05-22
13:15:26 UTC (rev 14277)
+++
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/HibernateValidator.java 2009-05-22
13:17:00 UTC (rev 14278)
@@ -91,8 +91,9 @@
*/
protected InvalidValue[] validateClass(Class<? extends Object> beanClass,
String property, Object value, Locale locale) {
- ClassValidator<? extends Object> classValidator = getValidator(
- beanClass, locale);
+ ClassValidator<? extends Object> classValidator =
+ getValidator(beanClass, locale);
+
InvalidValue[] invalidValues = classValidator
.getPotentialInvalidValues(property, value);
return invalidValues;
@@ -158,11 +159,11 @@
*/
protected InvalidValue[] validateBean(Object base, String property, Object value,
Locale locale) {
- Class<? extends Object> beanClass = base.getClass();
- InvalidValue[] invalidValues = validateClass(beanClass, property,
- value, locale);
- return invalidValues;
- }
+ Class<? extends Object> beanClass = base.getClass();
+
+ InvalidValue[] invalidValues = validateClass(beanClass, property, value, locale);
+ return invalidValues;
+ }
}