use of com.vaadin.server.UserError in project cuba by cuba-platform.
the class WebLookupPickerField method createComponent.
@Override
protected void createComponent() {
super.createComponent();
// delegate error indication
this.componentErrorHandler = message -> {
if (message instanceof UserError) {
return false;
}
pickerField.component.setComponentError(message);
return true;
};
component.setCustomValueEquals(InstanceUtils::propertyValueEquals);
final ComboBox selectComponent = component;
final WebPickerField.Picker picker = new WebPickerField.Picker(this, component) {
@Override
public void setRequired(boolean required) {
super.setRequired(required);
selectComponent.setNullSelectionAllowed(!required);
}
};
pickerField = new WebPickerField(picker);
// Required for custom components in fieldgroup
initValueSync(selectComponent, picker);
}
use of com.vaadin.server.UserError in project cuba by cuba-platform.
the class WebTimeField method createDatasourceWrapper.
@Override
protected ItemWrapper createDatasourceWrapper(Datasource datasource, Collection<MetaPropertyPath> propertyPaths) {
return new ItemWrapper(datasource, datasource.getMetaClass(), propertyPaths) {
private static final long serialVersionUID = 1729450322469573679L;
@Override
protected PropertyWrapper createPropertyWrapper(Object item, MetaPropertyPath propertyPath) {
return new PropertyWrapper(item, propertyPath) {
private static final long serialVersionUID = -4481934193197224070L;
@Override
public String getFormattedValue() {
Object value = this.getValue();
if (value instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
return sdf.format(value);
}
return super.getFormattedValue();
}
@Override
protected Object valueOf(Object newValue) throws Converter.ConversionException {
if (newValue instanceof String) {
if (StringUtils.isNotEmpty((String) newValue) && !newValue.equals(placeholder)) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
Date date = sdf.parse((String) newValue);
if (component.getComponentError() != null) {
component.setComponentError(null);
}
return date;
} catch (Exception e) {
LoggerFactory.getLogger(WebTimeField.class).debug("Unable to parse value of component " + getId() + "\n" + e.getMessage());
component.setComponentError(new UserError("Invalid value"));
return null;
}
} else
return null;
} else
return newValue;
}
};
}
};
}
Aggregations