use of org.apache.tapestry5.beanvalidator.ClientConstraintDescriptor in project tapestry-5 by apache.
the class BeanFieldValidator method render.
@Override
public void render(final MarkupWriter writer) {
final BeanValidationContext beanValidationContext = environment.peek(BeanValidationContext.class);
if (beanValidationContext == null) {
return;
}
final Validator validator = validatorFactory.getValidator();
final String currentProperty = beanValidationContext.getCurrentProperty();
if (currentProperty == null)
return;
final ValidationInfo validationInfo = getValidationInfo(beanValidationContext, currentProperty, validator);
final PropertyDescriptor propertyDescriptor = validationInfo.getPropertyDescriptor();
if (propertyDescriptor == null)
return;
for (final ConstraintDescriptor<?> descriptor : propertyDescriptor.getConstraintDescriptors()) {
Class<? extends Annotation> annotationType = descriptor.getAnnotation().annotationType();
ClientConstraintDescriptor clientConstraintDescriptor = clientValidatorSource.getConstraintDescriptor(annotationType);
if (clientConstraintDescriptor == null) {
continue;
}
String message = format("%s %s", field.getLabel(), interpolateMessage(descriptor));
Map<String, Object> attributes = CollectionFactory.newMap();
for (String attribute : clientConstraintDescriptor.getAttributes()) {
Object object = descriptor.getAttributes().get(attribute);
if (object == null) {
throw new NullPointerException(String.format("Attribute '%s' of %s is null but is required to apply client-side validation.", attribute, descriptor));
}
attributes.put(attribute, object);
}
clientConstraintDescriptor.applyClientValidation(writer, message, attributes);
}
}
Aggregations