use of com.haulmont.cuba.web.gui.data.PropertyWrapper 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