org.wicketstuff.jsr303.backups.PropertyValidator~0 Maven / Gradle / Ivy
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());
}
}
}