Author: vmolotkov
Date: 2008-04-10 11:27:18 -0400 (Thu, 10 Apr 2008)
New Revision: 7737
Modified:
trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
Log:
http://jira.jboss.com/jira/browse/RF-2045
Modified:
trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
===================================================================
---
trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2008-04-10
13:52:00 UTC (rev 7736)
+++
trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2008-04-10
15:27:18 UTC (rev 7737)
@@ -319,26 +319,60 @@
*
*/
protected void validateValue(FacesContext context, Object newValue) {
- // If our value is valid, enforce the required property if present
- if (isValid() && isRequired() && isEmpty(newValue)) {
- FacesMessage message = MessageUtil.getMessage(context,
- UIInput.REQUIRED_MESSAGE_ID,
- new Object[] {MessageUtil.getLabel(context, this)});
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ validateListValue(context, newValue, isEmpty(newValue), isRequired());
+ }
+
+ protected void validateListValue(FacesContext context, Object newValue,
+ boolean isEmpty, boolean isRequired) {
+ // If our value is valid, enforce the required property if present
+ requiredValidation(context, newValue, isEmpty, isRequired);
+
+ // If our value is valid and not empty, call all validators
+ processingValidators(context, newValue, isEmpty);
+ }
+
+ protected void requiredValidation(FacesContext context, Object newValue, boolean
isRequired, boolean isEmpty) {
+ if (isValid() && isRequired && isEmpty) {
+ FacesMessage message = MessageUtil.getMessage(context, UIInput.REQUIRED_MESSAGE_ID,
+ new Object[] {MessageUtil.getLabel(context, this)});
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- setValid(false);
+ context.addMessage(getClientId(context), message);
+ setValid(false);
+ }
+ }
+
+ protected void processingValidators(FacesContext context, Object newValue, boolean
isEmpty) {
+ if (isValid() && !isEmpty) {
+ Validator[] validators = getValidators();
+ for (int i = 0; i < validators.length; i++) {
+ Validator validator = (Validator) validators[i];
+ try {
+ 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 = ve.getFacesMessage();
+ if (message != null) {
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ context.addMessage(getClientId(context), message);
+ }
+ }
}
- // If our value is valid and not empty, call all validators
- if (isValid() && !isEmpty(newValue)) {
- Validator[] validators = getValidators();
- for (int i = 0; i < validators.length; i++) {
- Validator validator = (Validator) validators[i];
- try {
- validator.validate(context, this, newValue);
- }
- catch (ValidatorException ve) {
+ MethodBinding validator = getValidator();
+ if (validator != null) {
+ try {
+ validator.invoke(context,
+ new Object[] { context, this, newValue});
+ }
+ catch (EvaluationException ee) {
+ if (ee.getCause() instanceof ValidatorException) {
+ ValidatorException ve =
+ (ValidatorException) ee.getCause();
+
// If the validator throws an exception, we're
// invalid, and we need to add a message
setValid(false);
@@ -347,37 +381,15 @@
message.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(getClientId(context), message);
}
+ } else {
+ // Otherwise, rethrow the EvaluationException
+ throw ee;
}
}
-
- MethodBinding validator = getValidator();
- if (validator != null) {
- try {
- validator.invoke(context,
- new Object[] { context, this, newValue});
- }
- catch (EvaluationException ee) {
- if (ee.getCause() instanceof ValidatorException) {
- ValidatorException ve =
- (ValidatorException) ee.getCause();
-
- // If the validator throws an exception, we're
- // invalid, and we need to add a message
- setValid(false);
- FacesMessage message = ve.getFacesMessage();
- if (message != null) {
- message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);
- }
- } else {
- // Otherwise, rethrow the EvaluationException
- throw ee;
- }
- }
- }
}
+ }
}
-
+
/**
* <p>In addition to the standard <code>processUpdates</code>
behavior
* inherited from {@link UIComponentBase}, calls