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