Search in sources :

Example 1 with ValueConversionException

use of io.jmix.ui.component.data.ValueConversionException 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 ValueConversionException

use of io.jmix.ui.component.data.ValueConversionException 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 ValueConversionException

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

the class Param method createNumberField.

protected Component createNumberField(Datatype datatype, ValueProperty valueProperty) {
    if (inExpr) {
        ListEditor listEditor = uiComponents.create(ListEditor.class);
        listEditor.setItemType(ListEditorHelper.itemTypeFromDatatype(datatype));
        // listEditor.setDisplayValuesFieldEditable(true);
        initListEditor(listEditor, valueProperty);
        return listEditor;
    }
    TextField<String> field = uiComponents.create(TextField.NAME);
    field.addValueChangeListener(e -> {
        if (e.getValue() == null) {
            _setValue(e.getValue(), valueProperty);
        } else if (!StringUtils.isBlank(e.getValue())) {
            Object v;
            try {
                v = datatype.parse(e.getValue(), userSessionSource.getLocale());
            } catch (ValueConversionException ex) {
                showParseExceptionNotification(ex.getLocalizedMessage());
                return;
            } catch (ParseException ex) {
                showParseExceptionNotification(messages.getMainMessage("filter.param.numberInvalid"));
                return;
            }
            _setValue(v, valueProperty);
        } else if (StringUtils.isBlank(e.getValue())) {
            _setValue(null, valueProperty);
        } else {
            throw new IllegalStateException("Invalid value: " + e.getValue());
        }
    });
    field.setValue(datatype.format(_getValue(valueProperty), userSessionSource.getLocale()));
    return field;
}
Also used : ListEditor(com.haulmont.cuba.gui.components.ListEditor) ParseException(java.text.ParseException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException)

Example 4 with ValueConversionException

use of io.jmix.ui.component.data.ValueConversionException 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 5 with ValueConversionException

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

the class GroupTableImpl 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.getMessage("validationFail"));
            // rollback to previous value
            return false;
        }
    }
    return true;
}
Also used : GroupInfo(io.jmix.ui.component.data.GroupInfo) GroupAggregationInputValueChangeContext(io.jmix.ui.widget.JmixGroupTable.GroupAggregationInputValueChangeContext) ParseException(java.text.ParseException) GroupTableItems(io.jmix.ui.component.data.GroupTableItems) ValueConversionException(io.jmix.ui.component.data.ValueConversionException)

Aggregations

ValueConversionException (io.jmix.ui.component.data.ValueConversionException)6 ParseException (java.text.ParseException)6 ConversionException (io.jmix.ui.component.data.ConversionException)4 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)4 Nullable (javax.annotation.Nullable)4 ListEditor (com.haulmont.cuba.gui.components.ListEditor)1 GroupInfo (io.jmix.ui.component.data.GroupInfo)1 GroupTableItems (io.jmix.ui.component.data.GroupTableItems)1 GroupAggregationInputValueChangeContext (io.jmix.ui.widget.JmixGroupTable.GroupAggregationInputValueChangeContext)1