[richfaces-svn-commits] JBoss Rich Faces SVN: r11895 - in trunk: ui/listShuttle/src/main/java/org/richfaces/component and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Dec 18 13:43:01 EST 2008


Author: nbelaevski
Date: 2008-12-18 13:43:01 -0500 (Thu, 18 Dec 2008)
New Revision: 11895

Modified:
   trunk/samples/listShuttleDemo/src/main/webapp/WEB-INF/web.xml
   trunk/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java
   trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
   trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
Log:
https://jira.jboss.org/jira/browse/RF-4850

Modified: trunk/samples/listShuttleDemo/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/samples/listShuttleDemo/src/main/webapp/WEB-INF/web.xml	2008-12-18 17:18:33 UTC (rev 11894)
+++ trunk/samples/listShuttleDemo/src/main/webapp/WEB-INF/web.xml	2008-12-18 18:43:01 UTC (rev 11895)
@@ -3,14 +3,6 @@
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
-  	<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
-  	<param-value>com.sun.facelets.FaceletViewHandler</param-value>
- </context-param>
- <context-param>
- 	<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
- 	<param-value>.xhtml</param-value>
- </context-param>
- <context-param>
   <param-name>javax.faces.CONFIG_FILES</param-name>
   <param-value>/WEB-INF/faces-config.xml</param-value>
  </context-param>

Modified: trunk/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java
===================================================================
--- trunk/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java	2008-12-18 17:18:33 UTC (rev 11894)
+++ trunk/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java	2008-12-18 18:43:01 UTC (rev 11895)
@@ -644,36 +644,26 @@
 		}
 	}
 
-	protected boolean isEmpty(Object value) {
-		if (value == null) {
-			return true;
-		} else {
-			Object[] values = (Object[]) value;
-			
-			for (int i = 0; i < values.length; i++) {
-				Object v = values[i];
-				
-				if (!super.isEmpty(v)) {
-					return false;
-				}
-			}
-			
-			return true;
-		}
-	}
-	
-	protected boolean isListEmpty(Object value) {
-	    return super.isEmpty(value);
-	}
-	
 	protected void validateValue(FacesContext context, Object value) {
 	    Object[] values = (Object[]) value;
-	    boolean[] requiredValues = {isSourceRequired(), isTargetRequired()};
+
+	    Object sourceValue = values[0];
+	    Object targetValue = values[1];
 	    
-	    for (int i = 0; i < values.length; i++) {
-		Object v = values[i];
-		validateListValue(context, v, isListEmpty(v), requiredValues[i]);
+	    boolean sourceValueEmpty = isEmpty(sourceValue);
+	    boolean targetValueEmpty = isEmpty(targetValue);
+	    
+	    if (isValid() && sourceValueEmpty && isSourceRequired()) {
+		    requiredInvalidate(context);
 	    }
+
+	    if (isValid() && targetValueEmpty && isTargetRequired()) {
+		    requiredInvalidate(context);
+	    }
+	    
+	    if (isValid() && (!sourceValueEmpty || !targetValueEmpty)) {
+		    processValidators(context, value);
+	    }
 	}
 	
 	protected void resetDataModel() {

Modified: trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
===================================================================
--- trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java	2008-12-18 17:18:33 UTC (rev 11894)
+++ trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java	2008-12-18 18:43:01 UTC (rev 11895)
@@ -305,107 +305,59 @@
 		}
 	}
 
-	/**
-	 *
-	 * <p>Set the "valid" property according to the below algorithm.</p>
-	 *
-	 * <ul>
-	 *
-	 * <li>If the <code>valid</code> property on this component is still
-	 *     <code>true</code>, and the <code>required</code> property is also
-	 *     true, ensure that the local value is not empty (where "empty" is
-	 *     defined as <code>null</code> or a zero-length String.  If the local
-	 *     value is empty:
-	 *     <ul>
-	 *     <li>Enqueue an appropriate error message by calling the
-	 *         <code>addMessage()</code> method on the <code>FacesContext</code>
-	 *         instance for the current request.</li>
-	 *     <li>Set the <code>valid</code> property on this component to
-	 *         <code>false</code>.</li>
-	 *     </ul></li>
-	 * <li>If the <code>valid</code> property on this component is still
-	 *     <code>true</code>, and the local value is not empty, call the
-	 *     <code>validate()</code> method of each {@link Validator}
-	 *     registered for this {@link UIInput}, followed by the method
-	 *     pointed at by the <code>validatorBinding</code> property (if any).
-	 *     If any of these validators or the method throws a
-	 *     {@link ValidatorException}, catch the exception, add
-	 *     its message (if any) to the {@link FacesContext}, and set
-	 *     the <code>valid</code> property of this component to false.</li>
-	 *
-	 * </ul>
-	 *
-	 */
-	protected void validateValue(FacesContext context, Object newValue) {
-	    validateListValue(context, newValue, isEmpty(newValue), isRequired());
-	}
+	protected void requiredInvalidate(FacesContext context) {
+    	FacesMessage message = MessageUtil.getMessage(context, UIInput.REQUIRED_MESSAGE_ID, 
+    			new Object[] {MessageUtil.getLabel(context, this)});
+    	message.setSeverity(FacesMessage.SEVERITY_ERROR);
 
-	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);
+    	context.addMessage(getClientId(context), message);
+    	setValid(false);
 	}
 	
-	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);
-	    }
-	}
-	
-	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);
-				}
-			}
-		}
+	protected void processValidators(FacesContext context, Object 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) {
+    			// 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);
+    			}
+    		}
+    	}
 
-		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();
+    	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;
-				}
-			}
-		}
-	    }
+    				// 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;
+    			}
+    		}
+    	}
 	}
 	
 	/**

Modified: trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java
===================================================================
--- trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java	2008-12-18 17:18:33 UTC (rev 11894)
+++ trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingList.java	2008-12-18 18:43:01 UTC (rev 11895)
@@ -501,7 +501,19 @@
 		}
 	}
 
-
+	protected void validateValue(FacesContext context, Object newValue) {
+		if (isValid()) {
+			if (isEmpty(newValue)) {
+				if (isRequired()) {
+					requiredInvalidate(context);
+				}
+			} else {
+				processValidators(context, newValue);
+			}
+		}
+	}
+	
+	
 	// ------------------------------------------------------ Validation Methods
 
 




More information about the richfaces-svn-commits mailing list