Fixes issue 30405: selectors not working in grid view when display field is set
authorCarlos Aristu <carlos.aristu@openbravo.com>
Thu, 23 Jul 2015 13:25:31 +0200
changeset 27550 d5b668d83b8d
parent 27549 f6d7ef8a9f79
child 27551 bf251ca9947e
Fixes issue 30405: selectors not working in grid view when display field is set

When setting the display field for a selector with FKSelectorUIDefinition as its UI Definition class, if the display field was referencing to a property of the main entity of the selector, the display field name returned as part of the gridProps in the view definition was 'entity'.
The _extraProperties in the datasource used by the selector does not contain the entity name if they are referencing to the main entity. That is the root of the problem: when trying to set the selected value of the selector picklist in grid view, the display field name was never found as we were using 'entity' instead of looking directly for 'property'.
This problem does not affect when setting as display field a field that references a property which does not belong to the main entity of the selector.
To solve this problem, now in FKSelectorUIDefinition we return 'property' as the display field name instead of 'entity' when the property belongs to the main entity.
modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java
--- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java	Thu Jul 23 17:16:08 2015 +0200
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java	Thu Jul 23 13:25:31 2015 +0200
@@ -106,32 +106,11 @@
     String displayFieldName = JsonConstants.IDENTIFIER;
     if (displayField != null && displayField.getProperty() != null) {
       displayFieldName = displayField.getProperty();
+      return displayFieldName.replace(".", DalUtil.FIELDSEPARATOR);
     } else {
       // fallback to the default
       return null;
     }
-
-    if (!prop.getReferencedProperty().getEntity().hasProperty(getFirstProperty(displayFieldName))) {
-      // If the first property of the display field name does not belong to the referenced entity,
-      // return the displayFieldName
-      // Otherwise trying to append the displayFieldName to the referenced property would later
-      // result in an error
-      return displayFieldName.replace(".", DalUtil.FIELDSEPARATOR);
-    } else {
-      final String result = (prop.getName() + DalUtil.FIELDSEPARATOR + displayFieldName).replace(
-          ".", DalUtil.FIELDSEPARATOR);
-      return result;
-    }
-
-  }
-
-  private String getFirstProperty(String displayFieldName) {
-    int dotPosition = displayFieldName.indexOf(DalUtil.DOT);
-    if (dotPosition == -1) {
-      return displayFieldName;
-    } else {
-      return displayFieldName.substring(0, dotPosition);
-    }
   }
 
   public String getFieldProperties(Field field) {