details:   https://code.openbravo.com/erp/devel/pi/rev/6549f19a33f2
changeset: 19809:6549f19a33f2
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Wed Feb 27 13:46:25 2013 +0100
summary:   Fixes issue 22638: Enables using display fields in selectors based 
on views

The root problem was in the implementation of DalUtil.getValueFromPath. Two 
parameters are passed to that function, a BOB and a propertyPath. In selectors 
based on tables, the property always belongs to the BOB, but this is not always 
true for selectors based on views. I.e., in the Product selector, if the 
Product field is selected as value field and the Name field as display field, 
the following call will be made:

DalUtil.getValueFromPath(productBOB, "product.name").

The product BOB does not have a product (first part of product.name) property, 
but the view has. This has been solved by making recursive calls to 
getValueFromPath, stripping each time the first part of the propertyPath. This 
would be the execution for the previous example:
DalUtil.getValueFromPath(productBOB, "product.name")
   - The productBOB does not have a product property
   - return DalUtil.getValueFromPath(productBOB, "name")
      * The productBOB does have a name property, it returns its value

diffstat:

 src/org/openbravo/dal/core/DalUtil.java |  10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diffs (20 lines):

diff -r 2502e500a99d -r 6549f19a33f2 src/org/openbravo/dal/core/DalUtil.java
--- a/src/org/openbravo/dal/core/DalUtil.java   Wed Feb 27 11:00:03 2013 +0530
+++ b/src/org/openbravo/dal/core/DalUtil.java   Wed Feb 27 13:46:25 2013 +0100
@@ -154,7 +154,15 @@
       }
       final Entity currentEntity = currentBob.getEntity();
       if (!currentEntity.hasProperty(part)) {
-        return null;
+        // If the entity does not have the property, try with the following 
properties if possible
+        // This allows to use the display field in selectors based on views
+        // See issue https://issues.openbravo.com/view.php?id=22638
+        if (propertyPath.length() > part.length()) {
+          String nextParts = propertyPath.substring(propertyPath.indexOf(part) 
+ part.length() + 1);
+          return getValueFromPath(currentBob, nextParts);
+        } else {
+          return null;
+        }
       }
       value = currentBob.get(part);
       // if there is a next step, just make it

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to