You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2020/08/13 06:32:54 UTC

[ofbiz-framework] branch trunk updated: Fixed: multi-block attribute for html-template tag (OFBIZ-11686)

This is an automated email from the ASF dual-hosted git repository.

jamesyong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 3006523  Fixed: multi-block attribute for html-template tag (OFBIZ-11686)
3006523 is described below

commit 30065236b1b57c67b00ba11764eddf2bf78f906c
Author: James Yong <ja...@apache.org>
AuthorDate: Thu Aug 13 14:31:07 2020 +0800

    Fixed: multi-block attribute for html-template tag (OFBIZ-11686)
    
    Fixed regression where 1st of the 2 maps failed to render when accessing:
    https://localhost:8443/example/control/ExampleGeoLocationPointSet4
    https://localhost:8443/example/control/ExampleOsmGeoLocationPointSet4
---
 .../java/org/apache/ofbiz/widget/model/HtmlWidget.java    |  4 ++--
 .../ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java    | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
index 00d83d8..e1ee228 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/HtmlWidget.java
@@ -248,11 +248,11 @@ public class HtmlWidget extends ModelScreenWidget {
                 if (fileName.endsWith(".ftl")) {
                     fileName = fileName.substring(0, fileName.length() - 4);
                 }
-                MultiBlockHtmlTemplateUtil.putScriptInCache(context, fileName, scripts.toString());
+                String key = MultiBlockHtmlTemplateUtil.putScriptInCache(context, fileName, scripts.toString());
 
                 // construct script link
                 String webappName = (String) context.get("webappName");
-                String url = "/" + webappName + "/control/getJs?name=" + fileName;
+                String url = "/" + webappName + "/control/getJs?name=" + key;
 
                 // add csrf token to script link
                 HttpServletRequest request = (HttpServletRequest) context.get("request");
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
index 2a6f6e5..216412c 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/MultiBlockHtmlTemplateUtil.java
@@ -418,8 +418,9 @@ public final class MultiBlockHtmlTemplateUtil {
      * @param context
      * @param fileName
      * @param fileContent
+     * @return key used to store the script
      */
-    public static void putScriptInCache(Map<String, Object> context, String fileName, String fileContent) {
+    public static String putScriptInCache(Map<String, Object> context, String fileName, String fileContent) {
         HttpSession session = (HttpSession) context.get("session");
         String sessionId = session.getId();
         Map<String, String> scriptMap = UtilGenerics.cast(scriptCache.get(sessionId));
@@ -433,7 +434,17 @@ public final class MultiBlockHtmlTemplateUtil {
             };
             scriptCache.put(sessionId, scriptMap);
         }
-        scriptMap.put(fileName, fileContent);
+        String key = fileName;
+        if (scriptMap.containsKey(fileName)) {
+            int counter = 1;
+            key = fileName + "-" + counter;
+            while (scriptMap.containsKey(key)) {
+                counter++;
+                key = fileName + "-" + counter;
+            }
+        }
+        scriptMap.put(key, fileContent);
+        return key;
     }
 
     /**