From a493ea7ba3d429e1f7c3f6665ca281e891942ed2 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Thu, 19 Sep 2013 11:09:19 +0000 Subject: [PATCH] LookupPickerField doesn't find property #PL-2650 --- .../web/gui/components/WebPickerField.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java index 91d41bdbbe..889046ad48 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebPickerField.java @@ -6,7 +6,6 @@ package com.haulmont.cuba.web.gui.components; import com.haulmont.chile.core.model.Instance; import com.haulmont.chile.core.model.MetaClass; -import com.haulmont.chile.core.model.MetaPropertyPath; import com.haulmont.chile.core.model.utils.InstanceUtils; import com.haulmont.cuba.core.entity.Entity; import com.haulmont.cuba.gui.components.Action; @@ -121,15 +120,16 @@ public class WebPickerField public void setDatasource(Datasource datasource, String property) { this.datasource = datasource; - MetaClass metaClass = datasource.getMetaClass(); - this.metaProperty = metaClass.getProperty(property); - if (metaProperty == null) { + final MetaClass metaClass = datasource.getMetaClass(); + metaPropertyPath = metaClass.getPropertyPath(property); + try { + metaProperty = metaPropertyPath.getMetaProperty(); + } catch (ArrayIndexOutOfBoundsException e) { throw new RuntimeException(String.format("Property '%s' not found in class %s", property, metaClass)); } - final MetaPropertyPath propertyPath = new MetaPropertyPath(metaProperty.getDomain(), metaProperty); - final ItemWrapper wrapper = createDatasourceWrapper(datasource, Collections.singleton(propertyPath)); - final Property itemProperty = wrapper.getItemProperty(propertyPath); + final ItemWrapper wrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath)); + final Property itemProperty = wrapper.getItemProperty(metaPropertyPath); component.setPropertyDataSource(itemProperty); @@ -138,7 +138,7 @@ public class WebPickerField @Override public void itemChanged(Datasource ds, Entity prevItem, Entity item) { Object prevValue = getValue(); - Object newValue = InstanceUtils.getValueEx(item, propertyPath.getPath()); + Object newValue = InstanceUtils.getValueEx(item, metaPropertyPath.getPath()); setValue(newValue); fireValueChanged(prevValue, newValue); } @@ -146,7 +146,7 @@ public class WebPickerField @Override public void valueChanged(Entity source, String property, Object prevValue, Object value) { - if (property.equals(propertyPath.toString())) { + if (property.equals(metaPropertyPath.toString())) { setValue(value); fireValueChanged(prevValue, value); } @@ -155,9 +155,9 @@ public class WebPickerField ); if (datasource.getState() == Datasource.State.VALID && datasource.getItem() != null) { - if (property.equals(propertyPath.toString())) { + if (property.equals(metaPropertyPath.toString())) { Object prevValue = getValue(); - Object newValue = InstanceUtils.getValueEx(datasource.getItem(), propertyPath.getPath()); + Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath()); setValue(newValue); fireValueChanged(prevValue, newValue); }