diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java index a1039a2643..93a8b29f55 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java @@ -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 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 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); } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java index 1b616c14d1..8fa1340f29 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java @@ -38,6 +38,7 @@ import java.util.WeakHashMap; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.StringUtil; @@ -418,6 +419,8 @@ public final class MacroFormRenderer implements FormStringRenderer { sr.append(placeholder); sr.append("\" tabindex=\""); sr.append(tabindex); + sr.append("\" delegatorName=\""); + sr.append(((HttpSession)context.get("session")).getAttribute("delegatorName").toString()); sr.append("\" />"); executeMacro(writer, sr.toString()); ModelFormField.SubHyperlink subHyperlink = textField.getSubHyperlink(); @@ -2262,6 +2265,8 @@ public final class MacroFormRenderer implements FormStringRenderer { sr.append(lastViewName); sr.append("\" tabindex=\""); sr.append(tabindex); + sr.append("\" delegatorName=\""); + sr.append(((HttpSession)context.get("session")).getAttribute("delegatorName").toString()); sr.append("\" />"); executeMacro(writer, sr.toString()); this.addAsterisks(writer, context, modelFormField); diff --git a/framework/widget/templates/HtmlFormMacroLibrary.ftl b/framework/widget/templates/HtmlFormMacroLibrary.ftl index 1c616c4518..fb3fb2312e 100644 --- a/framework/widget/templates/HtmlFormMacroLibrary.ftl +++ b/framework/widget/templates/HtmlFormMacroLibrary.ftl @@ -48,7 +48,7 @@ under the License. <#macro renderHyperlinkField> -<#macro renderTextField name className alert value textSize maxlength id event action disabled clientAutocomplete ajaxUrl ajaxEnabled mask tabindex readonly placeholder=""> +<#macro renderTextField name className alert value textSize maxlength id event action disabled clientAutocomplete ajaxUrl ajaxEnabled mask tabindex readonly placeholder="" delegatorName="default"> <#if mask?has_content> <#lt/> @@ -631,8 +631,9 @@ Parameter: showDescription, String, optional - If the showDescription parameter Parameter: initiallyCollapsed, Not used. Parameter: lastViewName, String, optional - If the ajaxEnabled parameter is true, the contents of lastViewName will be appended to the Ajax URL. Parameter: tabindex, String, optional - HTML tabindex number. +Parameter: delegatorName, String, optional - name of the delegator in context. --> -<#macro renderLookupField name formName fieldFormName className="" alert="false" value="" size="" maxlength="" id="" event="" action="" readonly=false autocomplete="" descriptionFieldName="" targetParameterIter="" imgSrc="" ajaxUrl="" ajaxEnabled=javaScriptEnabled presentation="layer" width="" height="" position="" fadeBackground="true" clearText="" showDescription="" initiallyCollapsed="" lastViewName="main" tabindex=""> +<#macro renderLookupField name formName fieldFormName className="" alert="false" value="" size="" maxlength="" id="" event="" action="" readonly=false autocomplete="" descriptionFieldName="" targetParameterIter="" imgSrc="" ajaxUrl="" ajaxEnabled=javaScriptEnabled presentation="layer" width="" height="" position="" fadeBackground="true" clearText="" showDescription="" initiallyCollapsed="" lastViewName="main" tabindex="" delegatorName="default"> <#if Static["org.apache.ofbiz.widget.model.ModelWidget"].widgetBoundaryCommentsEnabled(context)><#-- context is always null here, but this is handled in widgetBoundaryCommentsEnabled --> @@ -641,7 +642,7 @@ Parameter: tabindex, String, optional - HTML tabindex number. <#local ajaxUrl = id + "," + ajaxUrl + ",ajaxLookup=Y" /> <#if (!showDescription?has_content)> - <#local showDescriptionProp = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.lookup.showDescription", "N", delegator)> + <#local showDescriptionProp = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.lookup.showDescription", "N", delegatorName)> <#if "Y" == showDescriptionProp> <#local showDescription = "true" /> <#else> @@ -649,13 +650,13 @@ Parameter: tabindex, String, optional - HTML tabindex number. <#if (!position?has_content)> - <#local position = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.lookup.position", "topleft", delegator)> + <#local position = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.lookup.position", "topleft", delegatorName)> <#if (!width?has_content)> - <#local width = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.lookup.width", "620", delegator)> + <#local width = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.lookup.width", "620", delegatorName)> <#if (!height?has_content)> - <#local height = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.lookup.height", "500", delegator)> + <#local height = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.lookup.height", "500", delegatorName)> <#if ajaxEnabled?has_content && ajaxEnabled>