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);
   }
 }
Ejemplo n.º 2
0
  /**
   * Robbed from {@link FormComponent}
   *
   * @param e
   * @param error
   */
  private void reportValidationError(ConversionException e, ValidationError error) {
    final Locale locale = e.getLocale();
    if (locale != null) {
      error.setVariable("locale", locale);
    }
    error.setVariable("exception", e);
    Format format = e.getFormat();
    if (format instanceof SimpleDateFormat) {
      error.setVariable("format", ((SimpleDateFormat) format).toLocalizedPattern());
    }

    Map<String, Object> variables = e.getVariables();
    if (variables != null) {
      error.getVariables().putAll(variables);
    }

    error((IValidationError) error);
  }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
  @Override
  protected ValidationError decorate(ValidationError error, IValidatable<Date> validatable) {
    error = super.decorate(error, validatable);

    error.setVariable("inputdate", validatable.getValue());

    // format variables if format has been specified
    if (format != null) {
      SimpleDateFormat sdf = new SimpleDateFormat(format);
      if (getMinimum() != null) {
        error.setVariable("minimum", sdf.format(getMinimum()));
      }
      if (getMaximum() != null) {
        error.setVariable("maximum", sdf.format(getMaximum()));
      }
      error.setVariable("inputdate", sdf.format(validatable.getValue()));
    }

    return error;
  }
Ejemplo n.º 5
0
 public void validate(IValidatable<List<FileUpload>> pValidatables) {
   for (FileUpload image : pValidatables.getValue()) {
     String extension = FilenameUtils.getExtension(image.getClientFileName());
     if (extension != null && !extensions.contains(extension.toLowerCase())) {
       ValidationError error = new ValidationError();
       error.addKey("WrongExtensionValidator");
       error.setVariable("extensions", extensions.toString());
       pValidatables.error(error);
     }
   }
 }
Ejemplo n.º 6
0
  @Override
  protected void convertInput() {
    Integer lower = this.lower.getConvertedInput();
    Integer upper = this.upper.getConvertedInput();

    if (lower != null && upper != null) {
      RangeValue value = new RangeValue(lower, upper);

      if (value.getLower() <= value.getUpper()) {
        this.setConvertedInput(value);
      } else {
        ValidationError error = new ValidationError();
        error.addKey("RangeSlider.ConversionError"); // wicket6
        error.setVariable("lower", value.getLower());
        error.setVariable("upper", value.getUpper());

        this.error(error);
      }
    }
  }
  // Methods //
  @Override
  protected void convertInput() {
    final IConverter<Date> converter = this.getConverter(Date.class);

    String dateInput = this.datePicker.getInput();
    String timeInput = this.timePicker.getInput();

    try {
      Date date =
          converter.convertToObject(this.formatInput(dateInput, timeInput), this.getLocale());
      this.setConvertedInput(date);
    } catch (ConversionException e) {
      ValidationError error = new ValidationError();
      error.addKey("DateTimePicker.ConversionError"); // wicket6
      error.setVariable("date", dateInput);
      error.setVariable("time", timeInput);

      this.error(error);
    }
  }