svn commit: r1785882 - in /ofbiz/ofbiz-framework/trunk/framework: entity/src/main/java/org/apache/ofbiz/entity/util/ widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/ widget/templates/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1785882 - in /ofbiz/ofbiz-framework/trunk/framework: entity/src/main/java/org/apache/ofbiz/entity/util/ widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/ widget/templates/

jleroux@apache.org
Author: jleroux
Date: Tue Mar  7 20:33:09 2017
New Revision: 1785882

URL: http://svn.apache.org/viewvc?rev=1785882&view=rev
Log:
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

Modified:
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
    ofbiz/ofbiz-framework/trunk/framework/widget/templates/HtmlFormMacroLibrary.ftl

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java?rev=1785882&r1=1785881&r2=1785882&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtilProperties.java Tue Mar  7 20:33:09 2017
@@ -40,6 +40,7 @@ import org.apache.ofbiz.base.util.UtilPr
 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
             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
                 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
             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);
@@ -152,6 +170,26 @@ public final class EntityUtilProperties
         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 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);
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java?rev=1785882&r1=1785881&r2=1785882&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java Tue Mar  7 20:33:09 2017
@@ -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 imp
         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 imp
         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);

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/templates/HtmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/templates/HtmlFormMacroLibrary.ftl?rev=1785882&r1=1785881&r2=1785882&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/templates/HtmlFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/templates/HtmlFormMacroLibrary.ftl Tue Mar  7 20:33:09 2017
@@ -48,7 +48,7 @@ under the License.
 </#macro>
 <#macro renderHyperlinkField></#macro>
 
-<#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>
     <script type="text/javascript">
       jQuery(function($){jQuery("#${id}").mask("${mask}");});
@@ -69,8 +69,8 @@ under the License.
     require
   /><#t/>
   <#if ajaxEnabled?has_content && ajaxEnabled>
-    <#assign defaultMinLength = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.autocompleter.defaultMinLength", delegator)>
-    <#assign defaultDelay = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.autocompleter.defaultDelay", delegator)>
+    <#assign defaultMinLength = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.autocompleter.defaultMinLength", delegatorName)>
+    <#assign defaultDelay = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.autocompleter.defaultDelay", delegatorName)>
     <script language="JavaScript" type="text/javascript">ajaxAutoCompleter('${ajaxUrl}', false, ${defaultMinLength!2}, ${defaultDelay!300});</script><#lt/>
   </#if>
 </#macro>
@@ -631,8 +631,9 @@ Parameter: showDescription, String, opti
 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 -->
   <!-- @renderLookupField -->
   </#if>
@@ -641,7 +642,7 @@ Parameter: tabindex, String, optional -
     <#local ajaxUrl = id + "," + ajaxUrl + ",ajaxLookup=Y" />
   </#if>
   <#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 -
     </#if>
   </#if>
   <#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>
   <#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>
   <#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>
   <#if ajaxEnabled?has_content && ajaxEnabled>
     <script type="text/javascript">
@@ -692,8 +693,8 @@ Parameter: tabindex, String, optional -
       );"></a><#rt>
     <#else>
       <#if ajaxEnabled?has_content && ajaxEnabled>
-        <#assign defaultMinLength = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.autocompleter.defaultMinLength", delegator)>
-        <#assign defaultDelay = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("widget", "widget.autocompleter.defaultDelay", delegator)>
+        <#assign defaultMinLength = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.autocompleter.defaultMinLength", delegatorName)>
+        <#assign defaultDelay = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValueFromDelegatorName("widget", "widget.autocompleter.defaultDelay", delegatorName)>
         <#local ajaxUrl = ajaxUrl + "&amp;_LAST_VIEW_NAME_=" + lastViewName />
         <#if !ajaxUrl?contains("searchValueFieldName=")>
           <#if descriptionFieldName?has_content && showDescription == "true">