Author: erwan
Date: Thu Sep 22 18:36:25 2011
New Revision: 1174308
URL:
http://svn.apache.org/viewvc?rev=1174308&view=revLog:
Resolving OFBIZ-4349 - commit r1077940 breaks the function to retrieve i18n translation from real entity underlying a view
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=1174308&r1=1174307&r2=1174308&view=diff==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Thu Sep 22 18:36:25 2011
@@ -814,11 +814,39 @@ public class GenericEntity extends Obser
keyBuffer.append('.');
keyBuffer.append(name);
// finish off by adding the values of all PK fields
- Iterator<ModelField> iter = modelEntity.getPksIterator();
- while (iter != null && iter.hasNext()) {
- ModelField curField = iter.next();
- keyBuffer.append('.');
- keyBuffer.append(this.get(curField.getName()));
+ if (modelEntity instanceof ModelViewEntity){
+ // retrieve pkNames of realEntity
+ ModelViewEntity modelViewEntiy = (ModelViewEntity) modelEntity;
+ List<String> pkNamesToUse = FastList.newInstance();
+ // iterate on realEntity for pkField
+ Iterator<ModelField> iter = modelEntityToUse.getPksIterator();
+ while (iter != null && iter.hasNext()) {
+ ModelField curField = iter.next();
+ String pkName = null;
+ Iterator<ModelAlias> iterAlias = modelViewEntiy.getAliasesIterator();
+ //search aliasName for pkField of realEntity
+ while (iterAlias != null && iterAlias.hasNext()) {
+ ModelAlias aliasField = iterAlias.next();
+ if (aliasField.getField().equals(curField.getName())){
+ pkName = aliasField.getName();
+ break;
+ }
+ }
+ if (pkName == null) pkName = curField.getName();
+ pkNamesToUse.add(pkName);
+ }
+ // read value with modelEntity name of pkNames
+ for (String pkName : pkNamesToUse) {
+ keyBuffer.append('.');
+ keyBuffer.append(this.get(pkName));
+ }
+ } else {
+ Iterator<ModelField> iter = modelEntity.getPksIterator();
+ while (iter != null && iter.hasNext()) {
+ ModelField curField = iter.next();
+ keyBuffer.append('.');
+ keyBuffer.append(this.get(curField.getName()));
+ }
}
String bundleKey = keyBuffer.toString();