Search in sources :

Example 1 with ValueConversionException

use of com.haulmont.chile.core.datatypes.ValueConversionException 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 2 with ValueConversionException

use of com.haulmont.chile.core.datatypes.ValueConversionException 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 ValueConversionException

use of com.haulmont.chile.core.datatypes.ValueConversionException 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 4 with ValueConversionException

use of com.haulmont.chile.core.datatypes.ValueConversionException in project cuba by cuba-platform.

the class WebGroupTable method distributeGroupAggregation.

@SuppressWarnings("unchecked")
protected boolean distributeGroupAggregation(AggregationInputValueChangeContext context) {
    if (distributionProvider != null) {
        String value = context.getValue();
        Object columnId = context.getColumnId();
        GroupInfo groupInfo = null;
        try {
            Object parsedValue = getParsedAggregationValue(value, columnId);
            Collection<E> scope = Collections.emptyList();
            if (context.isTotalAggregation()) {
                TableItems<E> tableItems = getItems();
                scope = tableItems == null ? Collections.emptyList() : tableItems.getItems();
            } else if (context instanceof GroupAggregationInputValueChangeContext) {
                Object groupId = ((GroupAggregationInputValueChangeContext) context).getGroupInfo();
                if (groupId instanceof GroupInfo) {
                    groupInfo = (GroupInfo) groupId;
                    scope = ((GroupTableItems) getItems()).getChildItems(groupInfo);
                }
            }
            GroupAggregationDistributionContext<E> aggregationDistribution = new GroupAggregationDistributionContext(getColumnNN(columnId.toString()), parsedValue, scope, groupInfo, context.isTotalAggregation());
            distributionProvider.onDistribution(aggregationDistribution);
        } catch (ValueConversionException e) {
            showParseErrorNotification(e.getLocalizedMessage());
            // rollback to previous value
            return false;
        } catch (ParseException e) {
            showParseErrorNotification(messages.getMainMessage("validationFail"));
            // rollback to previous value
            return false;
        }
    }
    return true;
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) GroupAggregationInputValueChangeContext(com.haulmont.cuba.web.widgets.CubaGroupTable.GroupAggregationInputValueChangeContext) ParseException(java.text.ParseException) GroupTableItems(com.haulmont.cuba.gui.components.data.GroupTableItems) ValueConversionException(com.haulmont.chile.core.datatypes.ValueConversionException)

Example 5 with ValueConversionException

use of com.haulmont.chile.core.datatypes.ValueConversionException 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)

Aggregations

ValueConversionException (com.haulmont.chile.core.datatypes.ValueConversionException)5 ParseException (java.text.ParseException)5 ConversionException (com.haulmont.cuba.gui.components.data.ConversionException)4 EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)4 GroupTableItems (com.haulmont.cuba.gui.components.data.GroupTableItems)1 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)1 GroupAggregationInputValueChangeContext (com.haulmont.cuba.web.widgets.CubaGroupTable.GroupAggregationInputValueChangeContext)1