public void validate(final IValidatable<Z> validatable) {
   final Z value = validatable.getValue();
   final Z min = this.getMinimum();
   final Z max = this.getMaximum();
   if ((min != null && ((Comparable) value).compareTo(min) < 0)
       || (max != null && ((Comparable) value).compareTo(max) > 0)) {
     final ValidationError error = new ValidationError();
     error.addMessageKey(this.resourceKey());
     if (min != null) {
       error.setVariable("minimum", min);
     }
     if (max != null) {
       error.setVariable("maximum", max);
     }
     validatable.error(error);
   }
 }
예제 #2
0
 @SuppressWarnings("unchecked")
 private Collection<T> convertInput(String[] inputs) {
   if (getType() == null) {
     try {
       return convertValue(inputs);
     } catch (ConversionException e) {
       ValidationError error = new ValidationError();
       if (e.getResourceKey() != null) {
         error.addMessageKey(e.getResourceKey());
       }
       if (e.getTargetType() != null) {
         error.addMessageKey("ConversionError." + Classes.simpleName(e.getTargetType()));
       }
       error.addMessageKey("ConversionError");
       reportValidationError(e, error);
     }
   } else {
     final IConverter converter = getConverter(getType());
     String curInput = "";
     try {
       Collection<T> convertedInput = new ArrayList<T>();
       if (inputs != null) {
         for (String input : inputs) {
           curInput = input;
           convertedInput.add(((T) converter.convertToObject(curInput, getLocale())));
         }
       }
       return convertedInput;
     } catch (ConversionException e) {
       ValidationError error = new ValidationError();
       if (e.getResourceKey() != null) {
         error.addMessageKey(e.getResourceKey());
       }
       String simpleName = Classes.simpleName(getType());
       error.addMessageKey("IConverter." + simpleName);
       error.addMessageKey("IConverter");
       error.setVariable("type", simpleName);
       error.setVariable("input", curInput);
       reportValidationError(e, error);
     }
   }
   return null;
 }