Search in sources :

Example 1 with ConversionException

use of com.haulmont.cuba.gui.components.data.ConversionException in project cuba by cuba-platform.

the class WebMaskedField method convertToModel.

@Override
protected V convertToModel(String componentRawValue) throws ConversionException {
    String value = emptyToNull(componentRawValue);
    if (datatype != null) {
        try {
            return datatype.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessage(), e);
        }
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
        try {
            return propertyDataType.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessage(), e);
        }
    }
    return super.convertToModel(value);
}
Also used : ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException)

Example 2 with ConversionException

use of com.haulmont.cuba.gui.components.data.ConversionException in project cuba by cuba-platform.

the class WebCurrencyField method convertToModel.

@Override
protected V convertToModel(String componentRawValue) throws ConversionException {
    String value = StringUtils.trimToNull(emptyToNull(componentRawValue));
    Datatype<V> datatype = getDatatypeInternal();
    if (datatype != null) {
        try {
            return datatype.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
        try {
            return propertyDataType.parse(componentRawValue, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    return super.convertToModel(componentRawValue);
}
Also used : ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException)

Example 3 with ConversionException

use of com.haulmont.cuba.gui.components.data.ConversionException in project cuba by cuba-platform.

the class WebAbstractTextArea method convertToModel.

@Override
protected V convertToModel(String componentRawValue) throws ConversionException {
    String value = emptyToNull(componentRawValue);
    if (isTrimming()) {
        value = StringUtils.trimToNull(value);
    }
    if (datatype != null) {
        try {
            return datatype.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
        try {
            return propertyDataType.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    return super.convertToModel(value);
}
Also used : ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException)

Example 4 with ConversionException

use of com.haulmont.cuba.gui.components.data.ConversionException in project cuba by cuba-platform.

the class WebTextField method convertToModel.

@Override
protected V convertToModel(String componentRawValue) throws ConversionException {
    String value = emptyToNull(componentRawValue);
    if (isTrimming()) {
        value = StringUtils.trimToNull(value);
    }
    if (datatype != null) {
        try {
            return datatype.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
        try {
            return propertyDataType.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    return super.convertToModel(value);
}
Also used : ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException)

Example 5 with ConversionException

use of com.haulmont.cuba.gui.components.data.ConversionException in project cuba by cuba-platform.

the class WebV8AbstractField method validate.

@Override
public void validate() throws ValidationException {
    if (hasValidationError()) {
        setValidationError(null);
    }
    if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) {
        return;
    }
    try {
        // if we cannot convert current presentation value into model - UI value is invalid
        convertToModel(component.getValue());
    } catch (ConversionException ce) {
        LoggerFactory.getLogger(getClass()).trace("Unable to convert presentation value to model", ce);
        setValidationError(ce.getLocalizedMessage());
        throw new ValidationException(ce.getLocalizedMessage());
    }
    if (isEmpty() && isRequired()) {
        String requiredMessage = getRequiredMessage();
        if (requiredMessage == null) {
            Messages messages = beanLocator.get(Messages.NAME);
            requiredMessage = messages.getMainMessage("validationFail.defaultRequiredMessage");
        }
        throw new RequiredValueMissingException(requiredMessage, this);
    }
    V value = getValue();
    triggerValidators(value);
}
Also used : ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) Messages(com.haulmont.cuba.core.global.Messages)

Aggregations

ConversionException (com.haulmont.cuba.gui.components.data.ConversionException)5 ValueConversionException (com.haulmont.chile.core.datatypes.ValueConversionException)4 EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)4 ParseException (java.text.ParseException)4 Messages (com.haulmont.cuba.core.global.Messages)1