Fixes issue 30404: selectors not working in grid view when display field is set
authorCarlos Aristu <carlos.aristu@openbravo.com>
Thu, 23 Jul 2015 13:51:40 +0200
changeset 27087 6273bf287bb7
parent 27086 06c15f9276a7
child 27088 7ea341ccbf45
Fixes issue 30404: 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	Fri Jul 17 15:04:27 2015 +0200
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java	Thu Jul 23 13:51:40 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) {