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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations