You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/09/21 15:29:34 UTC

svn commit: r448548 - in /myfaces/core/trunk/api/src/main/java/javax/faces/validator: LengthValidator.java NumberRangeValidator.java

Author: imario
Date: Thu Sep 21 06:29:33 2006
New Revision: 448548

URL: http://svn.apache.org/viewvc?view=rev&rev=448548
Log:
fixed NPE when checking a already converted value
fixed maximum message

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/validator/LengthValidator.java
    myfaces/core/trunk/api/src/main/java/javax/faces/validator/NumberRangeValidator.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/LengthValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/LengthValidator.java?view=diff&rev=448548&r1=448547&r2=448548
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/LengthValidator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/LengthValidator.java Thu Sep 21 06:29:33 2006
@@ -17,7 +17,7 @@
 
 /**
  * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html">JSF Specification</a>
- * 
+ *
  * @author Manfred Geiler (latest modification by $Author$)
  * @author Thomas Spiegl
  * @version $Revision$ $Date$
@@ -43,7 +43,7 @@
 
 	// Abstract methods implementation
 	protected Comparable getValue(Number number) {
-		return null;
+		return new Integer(number.toString().length());
 	}
 
 	protected Comparable getValue(String str) throws NumberFormatException {
@@ -61,7 +61,7 @@
 	protected String getTypeMessageId() {
 		return null;
 	}
-	
+
 	// SETTER & GETTER
 	public int getMaximum() {
 		return _maximum != null ? _maximum.intValue() : Integer.MAX_VALUE;

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/NumberRangeValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/NumberRangeValidator.java?view=diff&rev=448548&r1=448547&r2=448548
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/NumberRangeValidator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/NumberRangeValidator.java Thu Sep 21 06:29:33 2006
@@ -21,7 +21,7 @@
 
 /**
  * An abstract base class for all number range validators including LengthValidator
- * 
+ *
  * @author Nikolay Petrov
  * @version $Revision$ $Date$
  */
@@ -30,7 +30,7 @@
 	protected Number _minimum;
 	protected Number _maximum;
 	private boolean _transient = false;
-	
+
 	private boolean _checkRange;
 
 	public NumberRangeValidator(Number minimum, Number maximum) {
@@ -42,7 +42,7 @@
 		this._maximum = maximum;
 		this._checkRange = checkRange;
 	}
-	
+
 	public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
 		if (context == null) {
 			throw new NullPointerException("facesContext");
@@ -54,7 +54,7 @@
 		if (value == null) {
 			return;
 		}
-		
+
 		Comparable compValue = parseValue(context, component, value);
 		if (_checkRange && _minimum != null && _maximum != null && isNotInRange(compValue, _minimum, _maximum)) {
 			Object[] args = { _minimum, _maximum, component.getId()};
@@ -63,7 +63,7 @@
 			Object[] args = { _minimum, component.getId() };
 			throw new ValidatorException(_MessageUtils.getErrorMessage(context, getMinimumMessageId(), args));
 		} else if (_maximum != null && isBigger(compValue, _maximum)) {
-			Object[] args = { _minimum, component.getId() };
+			Object[] args = { _maximum, component.getId() };
 			throw new ValidatorException(_MessageUtils.getErrorMessage(context, getMaximumMessageId(), args));
 		}
 	}
@@ -73,7 +73,7 @@
 		if (value instanceof Number) {
 			return getValue((Number) value);
 		}
-		
+
 		try {
 			return getValue(value.toString());
 		} catch (NumberFormatException e) {
@@ -81,17 +81,17 @@
 			throw new ValidatorException(_MessageUtils.getErrorMessage(context, getTypeMessageId(), args));
 		}
 	}
-	
+
 	protected abstract Comparable getValue(Number number);
-	
+
 	protected abstract Comparable getValue(String str) throws NumberFormatException;
-	
+
 	protected abstract String getMinimumMessageId();
-	
+
 	protected abstract String getMaximumMessageId();
-	
+
 	protected abstract String getTypeMessageId();
-	
+
 	public boolean isTransient() {
 		return _transient;
 	}
@@ -136,12 +136,12 @@
 	private boolean isNotInRange(Comparable compValue, Number minValue, Number maxValue) {
 		return isSmaller(compValue, minValue) || isBigger(compValue, maxValue);
 	}
-	
+
 	private boolean isSmaller(Comparable compValue, Number other) {
 		return compValue.compareTo(other) < 0;
 	}
-	
+
 	private boolean isBigger(Comparable compValue, Number other) {
 		return compValue.compareTo(other) > 0;
-	}	
+	}
 }