Search in sources :

Example 1 with BeanValidator

use of com.haulmont.cuba.gui.components.validators.BeanValidator in project cuba by cuba-platform.

the class WebAbstractField method initBeanValidator.

protected void initBeanValidator() {
    MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
    MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
    Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass();
    if (enclosingJavaClass != KeyValueEntity.class && !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
        BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
        javax.validation.Validator validator = beanValidation.getValidator();
        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass);
        if (beanDescriptor.isBeanConstrained()) {
            addValidator(new BeanValidator(enclosingJavaClass, metaProperty.getName()));
        }
    }
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) BeanValidator(com.haulmont.cuba.gui.components.validators.BeanValidator) MetaClass(com.haulmont.chile.core.model.MetaClass) BeanValidation(com.haulmont.cuba.core.global.BeanValidation) BeanDescriptor(javax.validation.metadata.BeanDescriptor) MetaClass(com.haulmont.chile.core.model.MetaClass) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity)

Example 2 with BeanValidator

use of com.haulmont.cuba.gui.components.validators.BeanValidator in project cuba by cuba-platform.

the class DesktopAbstractField method initBeanValidator.

protected void initBeanValidator() {
    MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
    MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
    Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass();
    if (enclosingJavaClass != KeyValueEntity.class && !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
        BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
        javax.validation.Validator validator = beanValidation.getValidator();
        BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass);
        if (beanDescriptor.isBeanConstrained()) {
            addValidator(new BeanValidator(enclosingJavaClass, metaProperty.getName()));
        }
    }
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) BeanValidator(com.haulmont.cuba.gui.components.validators.BeanValidator) MetaClass(com.haulmont.chile.core.model.MetaClass) BeanValidation(com.haulmont.cuba.core.global.BeanValidation) BeanDescriptor(javax.validation.metadata.BeanDescriptor) MetaClass(com.haulmont.chile.core.model.MetaClass) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)2 KeyValueEntity (com.haulmont.cuba.core.entity.KeyValueEntity)2 BeanValidation (com.haulmont.cuba.core.global.BeanValidation)2 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)2 BeanValidator (com.haulmont.cuba.gui.components.validators.BeanValidator)2 BeanDescriptor (javax.validation.metadata.BeanDescriptor)2