From b61a981a45c5dd725c2da5aa452111b08a623217 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Fri, 8 Jul 2016 18:04:04 +0400 Subject: [PATCH] PL-7497 IllegalStateException when trying to edit entity with the dynamic attribute --- .../cuba/desktop/gui/components/DesktopAbstractTable.java | 4 ++-- .../haulmont/cuba/gui/components/EditorWindowDelegate.java | 4 ++-- .../haulmont/cuba/web/gui/components/WebLookupField.java | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractTable.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractTable.java index bb03bc0c2b..b202e2fe26 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractTable.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractTable.java @@ -687,7 +687,7 @@ public abstract class DesktopAbstractTable } if (e.getDs().getState() == Datasource.State.VALID && e.getDs().getItem() != null) { - if (e.getDs().containsItem(e.getDs().getItem())) { + if (e.getDs().containsItem(e.getDs().getItem().getId())) { newSelection.add((E) e.getDs().getItem()); } } @@ -1852,7 +1852,7 @@ public abstract class DesktopAbstractTable if (item != null) { setSelected(Collections.singleton(item)); } else { - setSelected(Collections.emptySet()); + setSelected(Collections.emptySet()); } } diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/EditorWindowDelegate.java b/modules/gui/src/com/haulmont/cuba/gui/components/EditorWindowDelegate.java index d8044bc1af..cfeffa7e86 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/EditorWindowDelegate.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/EditorWindowDelegate.java @@ -136,8 +136,8 @@ public class EditorWindowDelegate extends WindowDelegate { if (!PersistenceHelper.isNew(item) && !parentDs.getItemsToCreate().contains(item) && !parentDs.getItemsToUpdate().contains(item) && parentDs instanceof CollectionDatasource - && ((CollectionDatasource) parentDs).containsItem(item)) { - item = dataservice.reload(item, ds.getView(), ds.getMetaClass()); + && ((CollectionDatasource) parentDs).containsItem(item.getId())) { + item = dataservice.reload(item, ds.getView(), ds.getMetaClass(), ds.getLoadDynamicAttributes()); if (parentDs instanceof CollectionPropertyDatasourceImpl) { ((CollectionPropertyDatasourceImpl) parentDs).replaceItem(item); } else { diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java index dca656f6de..17c1f97f64 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebLookupField.java @@ -691,7 +691,12 @@ public class WebLookupField extends WebAbstractOptionsField implem protected void adoptMissingValue(Object value) { if (!ObjectUtils.equals(missingValue, value)) { - if (optionsDatasource != null && !optionsDatasource.containsItem(value)) { + Object itemId = null; + if (value instanceof Entity) { + itemId = ((Entity) value).getId(); + } + + if (optionsDatasource != null && !optionsDatasource.containsItem(itemId)) { missingValue = value; } else if (optionsList != null && !optionsList.contains(value)) { missingValue = value;