You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2021/03/06 15:06:39 UTC

[struts] branch WW-5117-reorders-stack created (now 4afa345)

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

lukaszlenart pushed a change to branch WW-5117-reorders-stack
in repository https://gitbox.apache.org/repos/asf/struts.git.


      at 4afa345  WW-5117 Moves action on top just before the tag

This branch includes the following new commits:

     new 4afa345  WW-5117 Moves action on top just before the tag

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[struts] 01/01: WW-5117 Moves action on top just before the tag

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5117-reorders-stack
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 4afa345c659c0fe75cd3a4c01dff749dcd0e84ea
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Mar 6 16:06:23 2021 +0100

    WW-5117 Moves action on top just before the tag
---
 .../components/template/FreemarkerTemplateEngine.java   | 11 ++++++++---
 .../resources/template/simple/dynamic-attributes.ftl    |  2 +-
 core/src/test/java/org/apache/struts2/TestAction.java   | 12 +++++++++++-
 .../org/apache/struts2/views/jsp/ui/HiddenTest.java     | 17 +++++++++++++++++
 .../org/apache/struts2/views/jsp/ui/Hidden-3.txt        |  5 +++++
 5 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java b/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java
index a272697..b3cb544 100644
--- a/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java
+++ b/core/src/main/java/org/apache/struts2/components/template/FreemarkerTemplateEngine.java
@@ -64,7 +64,7 @@ public class FreemarkerTemplateEngine extends BaseTemplateEngine {
     public void setFreemarkerManager(FreemarkerManager mgr) {
         this.freemarkerManager = mgr;
     }
-    
+
     public void renderTemplate(TemplateRenderingContext templateContext) throws Exception {
     	// get the various items required from the stack
         ValueStack stack = templateContext.getStack();
@@ -144,15 +144,20 @@ public class FreemarkerTemplateEngine extends BaseTemplateEngine {
             }
         };
 
+        LOG.debug("Puts action on the top of the stack, just before the tag");
+        Object actionFromStack = stack.pop();
         try {
             stack.push(templateContext.getTag());
+            stack.push(actionFromStack);
             template.process(model, writer);
         } finally {
-            stack.pop();
+            stack.pop(); // removes action
+            stack.pop(); // removes tag
+            stack.push(actionFromStack); // puts back action
         }
     }
 
     protected String getSuffix() {
         return "ftl";
     }
-}
\ No newline at end of file
+}
diff --git a/core/src/main/resources/template/simple/dynamic-attributes.ftl b/core/src/main/resources/template/simple/dynamic-attributes.ftl
index a6e3943..95de4b7 100644
--- a/core/src/main/resources/template/simple/dynamic-attributes.ftl
+++ b/core/src/main/resources/template/simple/dynamic-attributes.ftl
@@ -29,4 +29,4 @@
   </#if>
  ${aKey}="${value?html}"<#rt/>
 </#list><#rt/>
-</#if><#rt/>
\ No newline at end of file
+</#if><#rt/>
diff --git a/core/src/test/java/org/apache/struts2/TestAction.java b/core/src/test/java/org/apache/struts2/TestAction.java
index 97fa175..35b48b3 100644
--- a/core/src/test/java/org/apache/struts2/TestAction.java
+++ b/core/src/test/java/org/apache/struts2/TestAction.java
@@ -49,6 +49,7 @@ public class TestAction extends ActionSupport {
     private List list3;
     private SomeEnum status = SomeEnum.COMPLETED;
     private Float floatNumber;
+    private Long id;
 
     private final Map<String, String> texts = new HashMap<String, String>();
 
@@ -213,7 +214,7 @@ public class TestAction extends ActionSupport {
 	public void setStatus(SomeEnum status) {
 		this.status = status;
 	}
-    
+
     public List<SomeEnum> getStatusList() {
     	return Arrays.asList(SomeEnum.values());
     }
@@ -225,4 +226,13 @@ public class TestAction extends ActionSupport {
     public void setFloatNumber(Float floatNumber) {
         this.floatNumber = floatNumber;
     }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
 }
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java
index 37b5303..e66fc5a 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/HiddenTest.java
@@ -62,6 +62,23 @@ public class HiddenTest extends AbstractUITagTest {
         verify(TextFieldTag.class.getResource("Hidden-2.txt"));
     }
 
+    public void testDynamicAttributes() throws Exception {
+        TestAction testAction = (TestAction) action;
+        testAction.setId(27357L);
+
+        HiddenTag tag = new HiddenTag();
+        tag.setPageContext(pageContext);
+        tag.setId("einszwei");
+        tag.setName("first");
+        tag.setValue("%{id}");
+        tag.setDynamicAttribute("", "data-wuffmiauww", "%{id}");
+
+        tag.doStartTag();
+        tag.doEndTag();
+
+        verify(TextFieldTag.class.getResource("Hidden-3.txt"));
+    }
+
     /**
      * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
      * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Hidden-3.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Hidden-3.txt
new file mode 100644
index 0000000..c02c136
--- /dev/null
+++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Hidden-3.txt
@@ -0,0 +1,5 @@
+<tr style="display:none;">
+  <td colspan="2">
+    <input type="hidden" name="first" value="27357" id="einszwei" data-wuffmiauww="27357"/>
+  </td>
+</tr>