Fixed: Missing reference to the delegator in HtmlFormMacroLibrary.ftl
(OFBIZ-9230) This has been temporarily fixed with r1784259. After a discussion on dev ML and a code analysis reported in the Jira issue, I decided to follow Rishi Solanki's idea of using the delegatorName. Since we have no context when executing a macro in the widget form, I decided to pass it to the macro. I had though to create an EntityUtilProperties.getPropertyValueFromDelegatorName() method to eventually pass the delegatorName. Two macros were concerned renderLookupField and renderTextField. Note: while analysing the code I found that EntityExpr.checkRhsType() can face a related kind of problem. I'll commit an improvement later... Thanks: Wai for report and discussion and Rishi for pursuing his idea of using the delegatorName git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1785882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+43
-5
@@ -40,6 +40,7 @@ import org.apache.ofbiz.base.util.UtilProperties;
|
||||
import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.base.util.collections.ResourceBundleMapWrapper;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
import org.apache.ofbiz.entity.DelegatorFactory;
|
||||
import org.apache.ofbiz.entity.GenericEntityException;
|
||||
import org.apache.ofbiz.entity.GenericValue;
|
||||
|
||||
@@ -61,10 +62,6 @@ public final class EntityUtilProperties implements Serializable {
|
||||
return results;
|
||||
}
|
||||
resource = resource.replace(".properties", "");
|
||||
if (delegator == null) {
|
||||
Debug.logError("Could not get a system property for " + name + ". Reason: the delegator is null", module);
|
||||
return results;
|
||||
}
|
||||
try {
|
||||
GenericValue systemProperty = EntityQuery.use(delegator)
|
||||
.from("SystemProperty")
|
||||
@@ -82,7 +79,7 @@ public final class EntityUtilProperties implements Serializable {
|
||||
results.put("value", "");
|
||||
return results;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (GenericEntityException e) {
|
||||
Debug.logError("Could not get a system property for " + name + " : " + e.getMessage(), module);
|
||||
}
|
||||
return results;
|
||||
@@ -111,6 +108,27 @@ public final class EntityUtilProperties implements Serializable {
|
||||
return UtilProperties.getPropertyValue(resource, name, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPropertyValueFromDelegatorName(String resource, String name, String defaultValue, String delegatorName) {
|
||||
Delegator delegator = DelegatorFactory.getDelegator(delegatorName);
|
||||
if (delegator == null) { // This should not happen, but in case...
|
||||
Debug.logError("Could not get a delegator. Using the 'default' delegator", module);
|
||||
// this will be the common case for now as the delegator isn't available where we want to do this
|
||||
// we'll cheat a little here and assume the default delegator
|
||||
delegator = DelegatorFactory.getDelegator("default");
|
||||
Debug.logError("Could not get a delegator. Using the 'default' delegator", module);
|
||||
if (delegator == null) {
|
||||
Debug.logError("Could not get a system property for " + name + ". Reason: the delegator is null", module);
|
||||
}
|
||||
}
|
||||
Map<String, String> propMap = getSystemPropertyValue(resource, name, delegator);
|
||||
if ("Y".equals(propMap.get("isExistInDb"))) {
|
||||
String s = propMap.get("value");
|
||||
return (UtilValidate.isEmpty(s)) ? defaultValue : s;
|
||||
} else {
|
||||
return UtilProperties.getPropertyValue(resource, name, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static double getPropertyNumber(String resource, String name, double defaultValue) {
|
||||
return UtilProperties.getPropertyNumber(resource, name, defaultValue);
|
||||
@@ -157,6 +175,26 @@ public final class EntityUtilProperties implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPropertyValueFromDelegatorName(String resource, String name, String delegatorName) {
|
||||
Delegator delegator = DelegatorFactory.getDelegator(delegatorName);
|
||||
if (delegator == null) { // This should not happen, but in case...
|
||||
Debug.logError("Could not get a delegator. Using the 'default' delegator", module);
|
||||
// this will be the common case for now as the delegator isn't available where we want to do this
|
||||
// we'll cheat a little here and assume the default delegator
|
||||
delegator = DelegatorFactory.getDelegator("default");
|
||||
Debug.logError("Could not get a delegator. Using the 'default' delegator", module);
|
||||
if (delegator == null) {
|
||||
Debug.logError("Could not get a system property for " + name + ". Reason: the delegator is null", module);
|
||||
}
|
||||
}
|
||||
Map<String, String> propMap = getSystemPropertyValue(resource, name, delegator);
|
||||
if ("Y".equals(propMap.get("isExistInDb"))) {
|
||||
return propMap.get("value");
|
||||
} else {
|
||||
return UtilProperties.getPropertyValue(resource, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static Properties getProperties(String resource) {
|
||||
return UtilProperties.getProperties(resource);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user