Fixes issue 23890: The same hql is generated in the grid and in form view
authorAugusto Mauch <augusto.mauch@openbravo.com>
Tue, 28 May 2013 17:49:38 +0200
changeset 20487 3b9604eee5d7
parent 20486 f5a58673fad6
child 20488 768e5c072a99
Fixes issue 23890: The same hql is generated in the grid and in form view

The problem was that for that particular selector (Product selector), the generated displayfield string was 'product$product$name'. This is not correct, because the Product entity does not have a product property, the correct displayfield string is product$name. This has been fixed in the getDisplayFielName method of the FKSelectorUIDefinition class. A check has been added to make sure that the property used in the display field is part of the referenced entity. If it is not, then the displayFieldName is returned directly, instead of trying to append it to the referenced property.
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	Tue May 28 17:46:24 2013 +0200
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/reference/FKSelectorUIDefinition.java	Tue May 28 17:49:38 2013 +0200
@@ -110,9 +110,28 @@
       // fallback to the default
       return null;
     }
-    final String result = (prop.getName() + DalUtil.FIELDSEPARATOR + displayFieldName).replace(".",
-        DalUtil.FIELDSEPARATOR);
-    return result;
+
+    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) {