All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wicketstuff.jsr303.backups.PropertyValidator~0 Maven / Gradle / Ivy

There is a newer version: 6.30.0
Show newest version
package org.wicketstuff.jsr303;

import java.io.Serializable;
import java.util.Set;

import javax.validation.ConstraintViolation;

import org.apache.wicket.model.AbstractPropertyModel;
import org.apache.wicket.validation.INullAcceptingValidator;
import org.apache.wicket.validation.IValidatable;
import org.wicketstuff.jsr303.util.Assert;

class PropertyValidator implements INullAcceptingValidator, Serializable
{
    private static final long serialVersionUID = 1L;

    private final Class beanClass;
    private final String propertyExpression;

    PropertyValidator(final AbstractPropertyModel apm)
    {
        Assert.parameterNotNull(apm, "apm");
        this.beanClass = apm.getTarget().getClass();
        this.propertyExpression = apm.getPropertyExpression();
    }

    public void validate(final IValidatable validatable)
    {
        final T value = validatable.getValue();

        final Set violations = JSR303Validation.getValidator().validateValue(this.beanClass,
                this.propertyExpression, value);
        for (final Object v : violations)
        {
            validatable.error(new ViolationErrorBuilder.Property((ConstraintViolation) v).createError());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy