Search in sources :

Example 1 with ConversionException

use of io.jmix.ui.component.data.ConversionException in project jmix by jmix-framework.

the class CurrencyFieldImpl method convertToModel.

@Nullable
@Override
protected V convertToModel(@Nullable 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 : ValueConversionException(io.jmix.ui.component.data.ValueConversionException) ConversionException(io.jmix.ui.component.data.ConversionException) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) Nullable(javax.annotation.Nullable)

Example 2 with ConversionException

use of io.jmix.ui.component.data.ConversionException in project jmix by jmix-framework.

the class MaskedFieldImpl method convertToModel.

@Nullable
@Override
protected V convertToModel(@Nullable 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(io.jmix.ui.component.data.ConversionException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) Nullable(javax.annotation.Nullable)

Example 3 with ConversionException

use of io.jmix.ui.component.data.ConversionException in project jmix by jmix-framework.

the class AbstractTextArea method convertToModel.

@Nullable
@Override
protected V convertToModel(@Nullable 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 : ValueConversionException(io.jmix.ui.component.data.ValueConversionException) ConversionException(io.jmix.ui.component.data.ConversionException) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) Nullable(javax.annotation.Nullable)

Example 4 with ConversionException

use of io.jmix.ui.component.data.ConversionException in project jmix by jmix-framework.

the class TextFieldImpl method convertToModel.

@Nullable
@Override
protected V convertToModel(@Nullable 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(io.jmix.ui.component.data.ConversionException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) Nullable(javax.annotation.Nullable)

Aggregations

ConversionException (io.jmix.ui.component.data.ConversionException)4 ValueConversionException (io.jmix.ui.component.data.ValueConversionException)4 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)4 ParseException (java.text.ParseException)4 Nullable (javax.annotation.Nullable)4