@Override public ConstraintTarget getValidationAppliesTo() { return wrapped.getValidationAppliesTo(); } }
@Override public T getAnnotation() { return wrapped.getAnnotation(); }
@Override public Set<Class<?>> getGroups() { return wrapped.getGroups(); }
@Override public Map<String, Object> getAttributes() { return wrapped.getAttributes(); }
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( Size.class.equals( descriptor.getAnnotation().annotationType() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor; int max = sizeConstraint.getAnnotation().max(); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); Column col = (Column) selectable; if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } } }
public static Set<ConstraintDescriptor<?>> extractConstraintDescriptors(FacesContext context, PrimeApplicationContext applicationContext, ValueExpression ve, Class... groups) { PropertyDescriptor propertyDescriptor = extractPropertyDescriptor(context, applicationContext, ve); if (propertyDescriptor != null) { return propertyDescriptor.findConstraints().unorderedAndMatchingGroups(groups).getConstraintDescriptors(); } return null; }
public static Set<ConstraintDescriptor<?>> extractAllConstraintDescriptors(FacesContext context, PrimeApplicationContext applicationContext, ValueExpression ve) { PropertyDescriptor propertyDescriptor = extractPropertyDescriptor(context, applicationContext, ve); if (propertyDescriptor != null) { return propertyDescriptor.getConstraintDescriptors(); } return null; }
@Override public Set<ConstraintDescriptor<?>> getComposingConstraints() { return wrapped.getComposingConstraints(); }
@Override public Set<Class<? extends Payload>> getPayload() { return wrapped.getPayload(); }
@Override public List<Class<? extends ConstraintValidator<T, ?>>> getConstraintValidatorClasses() { return wrapped.getConstraintValidatorClasses(); }
@Override public boolean isReportAsSingleViolation() { return wrapped.isReportAsSingleViolation(); }
@Override public String getMessageTemplate() { return wrapped.getMessageTemplate(); }
/** * Determine a Spring-reported error code for the given constraint descriptor. * <p>The default implementation returns the simple class name of the descriptor's * annotation type. Note that the configured * {@link org.springframework.validation.MessageCodesResolver} will automatically * generate error code variations which include the object name and the field name. * @param descriptor the JSR-303 ConstraintDescriptor for the current violation * @return a corresponding error code (for use with {@link Errors}) * @since 4.2 * @see javax.validation.metadata.ConstraintDescriptor#getAnnotation() * @see org.springframework.validation.MessageCodesResolver */ protected String determineErrorCode(ConstraintDescriptor<?> descriptor) { return descriptor.getAnnotation().annotationType().getSimpleName(); }
@Override public Map<String, Object> getMetadata(ConstraintDescriptor constraintDescriptor) { Map<String, Object> metadata = new HashMap<>(); Map attrs = constraintDescriptor.getAttributes(); Object message = attrs.get(ATTR_MESSAGE); metadata.put(HTML.VALIDATION_METADATA.MAX_VALUE, attrs.get("value")); if (!message.equals(MESSAGE_ID)) { metadata.put(MESSAGE_METADATA, message); } return metadata; }
/** * Determine a Spring-reported error code for the given constraint descriptor. * <p>The default implementation returns the simple class name of the descriptor's * annotation type. Note that the configured * {@link org.springframework.validation.MessageCodesResolver} will automatically * generate error code variations which include the object name and the field name. * @param descriptor the JSR-303 ConstraintDescriptor for the current violation * @return a corresponding error code (for use with {@link Errors}) * @since 4.2 * @see javax.validation.metadata.ConstraintDescriptor#getAnnotation() * @see org.springframework.validation.MessageCodesResolver */ protected String determineErrorCode(ConstraintDescriptor<?> descriptor) { return descriptor.getAnnotation().annotationType().getSimpleName(); }
@Override public Map<String, Object> getMetadata(ConstraintDescriptor constraintDescriptor) { Map<String, Object> metadata = new HashMap<>(); Map attrs = constraintDescriptor.getAttributes(); Object message = attrs.get(ATTR_MESSAGE); metadata.put(HTML.VALIDATION_METADATA.DIGITS_INTEGER, attrs.get("integer")); metadata.put(HTML.VALIDATION_METADATA.DIGITS_FRACTION, attrs.get("fraction")); if (!message.equals(MESSAGE_ID)) { metadata.put(MESSAGE_METADATA, message); } return metadata; }
private static boolean isValidationMethod(ConstraintViolation<?> v) { return v.getConstraintDescriptor().getAnnotation() instanceof ValidationMethod; }
private static boolean isSelfValidating(ConstraintViolation<?> v) { return v.getConstraintDescriptor().getAnnotation() instanceof SelfValidating; }
public static <T> String format(ConstraintViolation<T> v) { if (v.getConstraintDescriptor().getAnnotation() instanceof ValidationMethod) { return v.getMessage(); } else { return String.format("%s %s", v.getPropertyPath(), v.getMessage()); } }
@Test public void testSimpleValidationWithClassLevel() { LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean(); validator.afterPropertiesSet(); ValidPerson person = new ValidPerson(); person.setName("Juergen"); person.getAddress().setStreet("Juergen's Street"); Set<ConstraintViolation<ValidPerson>> result = validator.validate(person); assertEquals(1, result.size()); Iterator<ConstraintViolation<ValidPerson>> iterator = result.iterator(); ConstraintViolation<?> cv = iterator.next(); assertEquals("", cv.getPropertyPath().toString()); assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NameAddressValid); }