Value doesn't set in LookupPickerField if we don's set datasource #PL-2648

This commit is contained in:
Yuriy Artamonov 2013-09-19 12:30:14 +00:00
parent aa3f8a05b3
commit 605386fae3
4 changed files with 10 additions and 60 deletions

View File

@ -169,12 +169,16 @@ public abstract class WebAbstractField<T extends com.vaadin.ui.Field>
final Object value = getValue();
Object newValue = fireValueChanging(prevValue, value);
fireValueChanged(prevValue, newValue);
final Object oldValue = prevValue;
prevValue = newValue;
if (!ObjectUtils.equals(value, newValue))
if (!ObjectUtils.equals(value, newValue)) {
WebAbstractField.this.component.setValue(newValue);
fireValueChanged(oldValue, newValue);
}
settingValue = false;
}
});

View File

@ -14,14 +14,10 @@ import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.DsContext;
import com.haulmont.cuba.web.gui.WebWindow;
import com.haulmont.cuba.web.gui.data.ItemWrapper;
import com.haulmont.cuba.web.gui.data.PropertyWrapper;
import com.haulmont.cuba.web.toolkit.ui.CubaCheckBox;
import com.haulmont.cuba.web.toolkit.ui.CubaFieldGroup;
import com.haulmont.cuba.web.toolkit.ui.CubaFieldGroupLayout;
import com.haulmont.cuba.web.toolkit.ui.CubaFieldWrapper;
import com.vaadin.data.Item;
import com.vaadin.data.util.converter.Converter;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;
@ -51,8 +47,6 @@ public class WebFieldGroup
protected int cols = 1;
protected Item itemWrapper;
protected Security security = AppBeans.get(Security.class);
protected MessageTools messageTools = AppBeans.get(MessageTools.class);
@ -302,8 +296,6 @@ public class WebFieldGroup
}
if (datasource != null) {
itemWrapper = createDatasourceWrapper(datasource, fieldsMetaProps);
if (!this.fields.isEmpty()) {
//Removes custom fieldsMetaProps from the list. We shouldn't to create components for custom fieldsMetaProps
for (MetaPropertyPath propertyPath : new ArrayList<>(fieldsMetaProps)) {
@ -696,10 +688,6 @@ public class WebFieldGroup
f.setCaption(caption);
}
protected ItemWrapper createDatasourceWrapper(Datasource datasource, Collection<MetaPropertyPath> propertyPaths) {
return new FieldGroupItemWrapper(datasource, propertyPaths);
}
@Override
public void postInit() {
}
@ -718,6 +706,8 @@ public class WebFieldGroup
public void validate() throws ValidationException {
final Map<Object, Exception> problems = new HashMap<>();
// todo use cuba fields for validation
for (FieldConfig field : getFields()) {
com.vaadin.ui.Field f = component.getField(field.getId());
if (f != null && f.isVisible() && f.isEnabled() && !f.isReadOnly()) {
@ -772,52 +762,6 @@ public class WebFieldGroup
}
}
public class FieldGroupItemWrapper extends ItemWrapper {
private static final long serialVersionUID = -7877886198903628220L;
public FieldGroupItemWrapper(Datasource datasource, Collection<MetaPropertyPath> propertyPaths) {
super(datasource, propertyPaths);
}
public Datasource getDatasource() {
return (Datasource) item;
}
@Override
protected PropertyWrapper createPropertyWrapper(Object item, MetaPropertyPath propertyPath) {
return new PropertyWrapper(item, propertyPath) {
@Override
public boolean isReadOnly() {
FieldConfig field = fields.get(propertyPath.toString());
return !isEditable(field);
}
@Override
public void setValue(Object newValue) throws ReadOnlyException, Converter.ConversionException {
if (newValue instanceof String) {
newValue = ((String) newValue).trim();
}
super.setValue(newValue);
}
@Override
public String getFormattedValue() {
Object value = getValue();
if (value == null) {
return "";
}
FieldConfig field = fields.get(propertyPath.toString());
if (field.getFormatter() != null) {
return field.getFormatter().format(value);
}
return super.getFormattedValue();
}
};
}
}
protected class WebFieldGroupFieldFactory extends com.haulmont.cuba.web.gui.components.AbstractFieldFactory {
@Override

View File

@ -52,6 +52,7 @@ public class WebLookupPickerField extends WebLookupField implements LookupPicker
};
pickerField = new WebPickerField(picker);
// Required for custom components in fieldgroup
initValueSync(selectComponent, picker);
}

View File

@ -38,6 +38,7 @@ public class WebSearchPickerField extends WebSearchField implements SearchPicker
};
pickerField = new WebPickerField(picker);
// Required for custom components in fieldgroup
initValueSync(selectComponent, picker);
}