[ofbiz-framework] branch trunk updated: Fixed: Apply multi-block attr to each application (OFBIZ-11706)

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

[ofbiz-framework] branch trunk updated: Fixed: Apply multi-block attr to each application (OFBIZ-11706)

James Yong-2
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 4dbdf72  Fixed: Apply multi-block attr to each application (OFBIZ-11706)
4dbdf72 is described below

commit 4dbdf720c5bfc349e8efd9aea2e9102548388b46
Author: James Yong <[hidden email]>
AuthorDate: Fri Jun 19 23:09:17 2020 +0800

    Fixed: Apply multi-block attr to each application (OFBIZ-11706)
   
    Rendering screen within freemarker template not done correctly when multi-block=true
   
    Thanks: Jacques for reporting
---
 .../java/org/apache/ofbiz/widget/model/HtmlWidget.java    | 15 +++++++++++++--
 .../org/apache/ofbiz/widget/renderer/ScreenRenderer.java  |  5 +++--
 2 files changed, 16 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 902cf8e..10a6ca1 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
@@ -28,6 +28,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Stack;
 
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
@@ -191,9 +192,19 @@ public class HtmlWidget extends ModelScreenWidget {
         String location = locationExdr.expandString(context);
 
         StringWriter stringWriter = new StringWriter();
-        context.put(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER, stringWriter);
+        Stack<StringWriter> stringWriterStack = UtilGenerics.cast(context.get(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER));
+        if (stringWriterStack == null) {
+            stringWriterStack = new Stack<>();
+        }
+        stringWriterStack.push(stringWriter);
+        // we use stack because a freemarker template may render a sub screen widget
+        context.put(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER, stringWriterStack);
         renderHtmlTemplate(stringWriter, locationExdr, context);
-        context.remove(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER);
+        stringWriterStack.pop();
+        // check if no more parent freemarker template before removing from context
+        if (stringWriterStack.empty()) {
+            context.remove(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER);
+        }
         String data = stringWriter.toString();
         stringWriter.close();
 
diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java
index 6724ad7..6551667 100644
--- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java
+++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/ScreenRenderer.java
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.Stack;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -139,8 +140,8 @@ public class ScreenRenderer {
         } else {
             context.put("renderFormSeqNumber", String.valueOf(renderFormSeqNumber));
             if (context.get(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER) != null) {
-                StringWriter stringWriter = (StringWriter) context.get(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER);
-                modelScreen.renderScreenString(stringWriter, context, screenStringRenderer);
+                Stack<StringWriter> stringWriterStack = UtilGenerics.cast(context.get(MultiBlockHtmlTemplateUtil.MULTI_BLOCK_WRITER));
+                modelScreen.renderScreenString(stringWriterStack.peek(), context, screenStringRenderer);
             } else {
                 modelScreen.renderScreenString(writer, context, screenStringRenderer);
             }