Example usage for org.apache.wicket.validation ValidationError setVariable

List of usage examples for org.apache.wicket.validation ValidationError setVariable

Introduction

In this page you can find the example usage for org.apache.wicket.validation ValidationError setVariable.

Prototype

public ValidationError setVariable(String name, Object value) 

Source Link

Document

Sets a key and value in the variables map for use in substitution.

Usage

From source file:au.org.theark.study.web.component.managestudy.StudyLogoValidator.java

License:Open Source License

public void validate(IValidatable<List<FileUpload>> pValidatable) {

    List<FileUpload> fileUploadList = pValidatable.getValue();

    for (FileUpload fileUploadImage : fileUploadList) {

        String fileExtension = StringUtils.getFilenameExtension(fileUploadImage.getClientFileName());
        ValidationError error = new ValidationError();

        try {/*from ww  w. j  a  v  a  2s .co  m*/
            // Check extension ok
            if (fileExtension != null && !fileExtensions.contains(fileExtension.toLowerCase())) {
                error.addMessageKey("study.studyLogoFileType");
                error.setVariable("extensions", fileExtensions.toString());
                pValidatable.error(error);
            } // Check size ok
            else if (fileUploadImage.getSize() > fileSize.bytes()) {
                error.addMessageKey("study.studyLogoFileSize");
                pValidatable.error(error);
            } else {
                // Read image, to work out width and height
                image = new SerializableBufferedImage(ImageIO.read(fileUploadImage.getInputStream()));

                if (image.getHeight() > 100) {
                    error.addMessageKey("study.studyLogoPixelSize");
                    pValidatable.error(error);
                }
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
            error.addMessageKey("study.studyLogoImageError");
            pValidatable.error(error);
        }

    }

}

From source file:com.googlecode.wicket.jquery.ui.form.slider.RangeSlider.java

License:Apache License

@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 {//from   w  w  w .j  av  a  2 s  .c  o m
            ValidationError error = new ValidationError();
            error.addKey("RangeSlider.ConversionError"); //wicket6
            error.setVariable("lower", value.getLower());
            error.setVariable("upper", value.getUpper());

            this.error(error);
        }
    }
}

From source file:com.googlecode.wicket.jquery.ui.kendo.datetime.DateTimePicker.java

License:Apache License

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

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

    try {/*  w w w. j a  v  a2s . c  o m*/
        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);
    }
}

From source file:com.googlecode.wicket.kendo.ui.form.datetime.AjaxDateTimePicker.java

License:Apache License

@Override
public void convertInput() {
    final IConverter<Date> converter = this.getConverter(Date.class);

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

    try {/*from w  w w.ja  v a2s.  c  o  m*/
        String value = this.formatInput(dateInput, timeInput);
        this.setConvertedInput(converter.convertToObject(value, this.getLocale()));
    } catch (ConversionException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getMessage(), e);
        }

        ValidationError error = new ValidationError();
        error.addKey("AjaxDateTimePicker.ConversionError"); // wicket6
        error.setVariable("date", dateInput);
        error.setVariable("time", timeInput);

        this.error(error);
    }
}

From source file:com.googlecode.wicket.kendo.ui.form.datetime.local.AjaxDateTimePicker.java

License:Apache License

@Override
public void convertInput() {
    final IConverter<LocalDateTime> converter = this.getConverter(LocalDateTime.class);

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

    try {/*from w w w  . j  av  a  2  s.c o  m*/
        String value = this.formatInput(dateInput, timeInput);
        this.setConvertedInput(converter.convertToObject(value, this.getLocale()));
    } catch (ConversionException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getMessage(), e);
        }

        ValidationError error = new ValidationError();
        error.addKey("AjaxDateTimePicker.ConversionError"); // wicket6
        error.setVariable("date", dateInput);
        error.setVariable("time", timeInput);

        this.error(error);
    }
}

From source file:com.myamamoto.wicket.misc.compound.NotNullValidator.java

License:Apache License

public void validate(IValidatable<T> validatable) {
    if (null == validatable.getValue()) {
        ValidationError error = new ValidationError();
        error.addMessageKey("Required");
        error.setVariable("label", label);
        validatable.error(error);/*from  w ww .  java 2s  . c  o  m*/
    }
}

From source file:com.myamamoto.wicket.misc.compound.PersonValidator.java

License:Apache License

PersonValidator() {
    nameNotNullValidator = new NotNullValidator("name");
    ageNotNullValidator = new NotNullValidator("age");
    nameValidator = new CompoundValidator<String>();
    ageValidator = new CompoundValidator<Integer>();
    ageValidator.add(new MinimumValidator<Integer>(0) {
        public void validate(IValidatable<Integer> validatable) {
            Integer value = validatable.getValue();
            Integer minimum = getMinimum();
            if (value.compareTo(minimum) < 0) {
                ValidationError error = new ValidationError();
                error.addMessageKey(resourceKey());
                error.setVariable("minimum", minimum);
                error.setVariable("input", value);
                error.setVariable("label", "age");
                validatable.error(error);
            }//from   ww  w  . jav a2 s .  com
        }
    });
}

From source file:name.martingeisse.wicket.autoform.annotation.validation.palette.IntegerRangeValidator.java

License:Open Source License

@Override
public void validate(IValidatable<Integer> validatable) {
    int actualValue = validatable.getValue();
    if ((isMinimum && actualValue < value) || (!isMinimum && actualValue > value)) {
        ValidationError error = new ValidationError(this, isMinimum ? "minimum" : "maximum");
        error.setVariable("value", validatable.getValue());
        error.setVariable(isMinimum ? "minimum" : "maximum", value);
        validatable.error(error);/*from ww w . j a v  a 2 s  .co  m*/
    }
}

From source file:name.martingeisse.wicket.autoform.annotation.validation.palette.StringLengthValidator.java

License:Open Source License

@Override
public void validate(IValidatable<String> validatable) {
    int length = validatable.getValue().length();
    if ((minLength >= 0 && length < minLength) || (maxLength >= 0 && length > maxLength)) {
        ValidationError error = new ValidationError(this, getVariation());
        error.setVariable("length", validatable.getValue().length());
        if (minLength >= 0 && maxLength >= 0 && minLength == maxLength) {
            error.setVariable("exact", minLength);
        } else {//w w w  . ja  va2 s  .c o m
            if (minLength >= 0) {
                error.setVariable("minimum", minLength);
            }
            if (maxLength >= 0) {
                error.setVariable("maximum", maxLength);
            }
        }
        validatable.error(error);
    }
}

From source file:net.ftlines.wicket.validation.bean.ViolationConverter.java

License:Apache License

@Override
public <T> ValidationError convert(ConstraintViolation<T> violation) {
    ConstraintDescriptor<?> desc = violation.getConstraintDescriptor();

    ValidationError error = new ValidationError();
    error.setMessage(violation.getMessage());
    addMessageKey(error, desc, "message");

    // TODO figure out how to handle composite constraints, see desc.isReportAsSingleViolation()

    for (String key : desc.getAttributes().keySet()) {
        error.setVariable(key, desc.getAttributes().get(key));
    }/*from   ww w.  j  ava  2  s.  c o m*/
    return error;
}