# HG changeset patch
# User Carlos Aristu <carlos.aristu@openbravo.com>
# Date 1437577370 -7200
#      Wed Jul 22 17:02:50 2015 +0200
# Node ID cd1ddf017185991943a616cae587cd15f35d3a5a
# Parent  dcf8b6e81b7b01c3c54a37e2780bd43f7720e6a5
Fixes issue 30403: 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.

diff --git a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java b/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
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java
@@ -106,23 +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) {
